code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
/*! * Farbtastic: jQuery color picker plug-in v1.3u * * Licensed under the GPL license: * http://www.gnu.org/licenses/gpl.html */ (function($) { $.fn.farbtastic = function (options) { $.farbtastic(this, options); return this; }; $.farbtastic = function (container, callback) { var container = $(container).get(0); return container.farbtastic || (container.farbtastic = new $._farbtastic(container, callback)); }; $._farbtastic = function (container, callback) { // Store farbtastic object var fb = this; // Insert markup $(container).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>'); var e = $('.farbtastic', container); fb.wheel = $('.wheel', container).get(0); // Dimensions fb.radius = 84; fb.square = 100; fb.width = 194; // Fix background PNGs in IE6 if (navigator.appVersion.match(/MSIE [0-6]\./)) { $('*', e).each(function () { if (this.currentStyle.backgroundImage != 'none') { var image = this.currentStyle.backgroundImage; image = this.currentStyle.backgroundImage.substring(5, image.length - 2); $(this).css({ 'backgroundImage': 'none', 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')" }); } }); } /** * Link to the given element(s) or callback. */ fb.linkTo = function (callback) { // Unbind previous nodes if (typeof fb.callback == 'object') { $(fb.callback).unbind('keyup', fb.updateValue); } // Reset color fb.color = null; // Bind callback or elements if (typeof callback == 'function') { fb.callback = callback; } else if (typeof callback == 'object' || typeof callback == 'string') { fb.callback = $(callback); fb.callback.bind('keyup', fb.updateValue); if (fb.callback.get(0).value) { fb.setColor(fb.callback.get(0).value); } } return this; }; fb.updateValue = function (event) { if (this.value && this.value != fb.color) { fb.setColor(this.value); } }; /** * Change color with HTML syntax #123456 */ fb.setColor = function (color) { var unpack = fb.unpack(color); if (fb.color != color && unpack) { fb.color = color; fb.rgb = unpack; fb.hsl = fb.RGBToHSL(fb.rgb); fb.updateDisplay(); } return this; }; /** * Change color with HSL triplet [0..1, 0..1, 0..1] */ fb.setHSL = function (hsl) { fb.hsl = hsl; fb.rgb = fb.HSLToRGB(hsl); fb.color = fb.pack(fb.rgb); fb.updateDisplay(); return this; }; ///////////////////////////////////////////////////// /** * Retrieve the coordinates of the given event relative to the center * of the widget. */ fb.widgetCoords = function (event) { var offset = $(fb.wheel).offset(); return { x: (event.pageX - offset.left) - fb.width / 2, y: (event.pageY - offset.top) - fb.width / 2 }; }; /** * Mousedown handler */ fb.mousedown = function (event) { // Capture mouse if (!document.dragging) { $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup); document.dragging = true; } // Check which area is being dragged var pos = fb.widgetCoords(event); fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square; // Process fb.mousemove(event); return false; }; /** * Mousemove handler */ fb.mousemove = function (event) { // Get coordinates relative to color picker center var pos = fb.widgetCoords(event); // Set new HSL parameters if (fb.circleDrag) { var hue = Math.atan2(pos.x, -pos.y) / 6.28; if (hue < 0) hue += 1; fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]); } else { var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5)); var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5)); fb.setHSL([fb.hsl[0], sat, lum]); } return false; }; /** * Mouseup handler */ fb.mouseup = function () { // Uncapture mouse $(document).unbind('mousemove', fb.mousemove); $(document).unbind('mouseup', fb.mouseup); document.dragging = false; }; /** * Update the markers and styles */ fb.updateDisplay = function () { // Markers var angle = fb.hsl[0] * 6.28; $('.h-marker', e).css({ left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px', top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px' }); $('.sl-marker', e).css({ left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px', top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px' }); // Saturation/Luminance gradient $('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5]))); // Linked elements or callback if (typeof fb.callback == 'object') { // Set background/foreground color $(fb.callback).css({ backgroundColor: fb.color, color: fb.hsl[2] > 0.5 ? '#000' : '#fff' }); // Change linked value $(fb.callback).each(function() { if (this.value && this.value != fb.color) { this.value = fb.color; } }); } else if (typeof fb.callback == 'function') { fb.callback.call(fb, fb.color); } }; /* Various color utility functions */ fb.pack = function (rgb) { var r = Math.round(rgb[0] * 255); var g = Math.round(rgb[1] * 255); var b = Math.round(rgb[2] * 255); return '#' + (r < 16 ? '0' : '') + r.toString(16) + (g < 16 ? '0' : '') + g.toString(16) + (b < 16 ? '0' : '') + b.toString(16); }; fb.unpack = function (color) { if (color.length == 7) { return [parseInt('0x' + color.substring(1, 3)) / 255, parseInt('0x' + color.substring(3, 5)) / 255, parseInt('0x' + color.substring(5, 7)) / 255]; } else if (color.length == 4) { return [parseInt('0x' + color.substring(1, 2)) / 15, parseInt('0x' + color.substring(2, 3)) / 15, parseInt('0x' + color.substring(3, 4)) / 15]; } }; fb.HSLToRGB = function (hsl) { var m1, m2, r, g, b; var h = hsl[0], s = hsl[1], l = hsl[2]; m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s; m1 = l * 2 - m2; return [this.hueToRGB(m1, m2, h+0.33333), this.hueToRGB(m1, m2, h), this.hueToRGB(m1, m2, h-0.33333)]; }; fb.hueToRGB = function (m1, m2, h) { h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h); if (h * 6 < 1) return m1 + (m2 - m1) * h * 6; if (h * 2 < 1) return m2; if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6; return m1; }; fb.RGBToHSL = function (rgb) { var min, max, delta, h, s, l; var r = rgb[0], g = rgb[1], b = rgb[2]; min = Math.min(r, Math.min(g, b)); max = Math.max(r, Math.max(g, b)); delta = max - min; l = (min + max) / 2; s = 0; if (l > 0 && l < 1) { s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l)); } h = 0; if (delta > 0) { if (max == r && max != g) h += (g - b) / delta; if (max == g && max != b) h += (2 + (b - r) / delta); if (max == b && max != r) h += (4 + (r - g) / delta); h /= 6; } return [h, s, l]; }; // Install mousedown handler (the others are set on the document on-demand) $('*', e).mousedown(fb.mousedown); // Init color fb.setColor('#000000'); // Set linked elements/callback if (callback) { fb.linkTo(callback); } }; })(jQuery);
01happy-blog
trunk/myblog/wp-admin/js/farbtastic.js
JavaScript
oos
7,689
var tagBox, commentsBox, editPermalink, makeSlugeditClickable, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint; // return an array with any duplicate, whitespace or values removed function array_unique_noempty(a) { var out = []; jQuery.each( a, function(key, val) { val = jQuery.trim(val); if ( val && jQuery.inArray(val, out) == -1 ) out.push(val); } ); return out; } (function($){ tagBox = { clean : function(tags) { var comma = postL10n.comma; if ( ',' !== comma ) tags = tags.replace(new RegExp(comma, 'g'), ','); tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, ''); if ( ',' !== comma ) tags = tags.replace(/,/g, comma); return tags; }, parseTags : function(el) { var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'), thetags = taxbox.find('.the-tags'), comma = postL10n.comma, current_tags = thetags.val().split(comma), new_tags = []; delete current_tags[num]; $.each( current_tags, function(key, val) { val = $.trim(val); if ( val ) { new_tags.push(val); } }); thetags.val( this.clean( new_tags.join(comma) ) ); this.quickClicks(taxbox); return false; }, quickClicks : function(el) { var thetags = $('.the-tags', el), tagchecklist = $('.tagchecklist', el), id = $(el).attr('id'), current_tags, disabled; if ( !thetags.length ) return; disabled = thetags.prop('disabled'); current_tags = thetags.val().split(postL10n.comma); tagchecklist.empty(); $.each( current_tags, function( key, val ) { var span, xbutton; val = $.trim( val ); if ( ! val ) return; // Create a new span, and ensure the text is properly escaped. span = $('<span />').text( val ); // If tags editing isn't disabled, create the X button. if ( ! disabled ) { xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' ); xbutton.click( function(){ tagBox.parseTags(this); }); span.prepend('&nbsp;').prepend( xbutton ); } // Append the span to the tag list. tagchecklist.append( span ); }); }, flushTags : function(el, a, f) { a = a || false; var tags = $('.the-tags', el), newtag = $('input.newtag', el), comma = postL10n.comma, newtags, text; text = a ? $(a).text() : newtag.val(); tagsval = tags.val(); newtags = tagsval ? tagsval + comma + text : text; newtags = this.clean( newtags ); newtags = array_unique_noempty( newtags.split(comma) ).join(comma); tags.val(newtags); this.quickClicks(el); if ( !a ) newtag.val(''); if ( 'undefined' == typeof(f) ) newtag.focus(); return false; }, get : function(id) { var tax = id.substr(id.indexOf('-')+1); $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) { if ( 0 == r || 'success' != stat ) r = wpAjax.broken; r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>'); $('a', r).click(function(){ tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this); return false; }); $('#'+id).after(r); }); }, init : function() { var t = this, ajaxtag = $('div.ajaxtag'); $('.tagsdiv').each( function() { tagBox.quickClicks(this); }); $('input.tagadd', ajaxtag).click(function(){ t.flushTags( $(this).closest('.tagsdiv') ); }); $('div.taghint', ajaxtag).click(function(){ $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus(); }); $('input.newtag', ajaxtag).blur(function() { if ( this.value == '' ) $(this).parent().siblings('.taghint').css('visibility', ''); }).focus(function(){ $(this).parent().siblings('.taghint').css('visibility', 'hidden'); }).keyup(function(e){ if ( 13 == e.which ) { tagBox.flushTags( $(this).closest('.tagsdiv') ); return false; } }).keypress(function(e){ if ( 13 == e.which ) { e.preventDefault(); return false; } }).each(function(){ var tax = $(this).closest('div.tagsdiv').attr('id'); $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } ); }); // save tags on post save/publish $('#post').submit(function(){ $('div.tagsdiv').each( function() { tagBox.flushTags(this, false, 1); }); }); // tag cloud $('a.tagcloud-link').click(function(){ tagBox.get( $(this).attr('id') ); $(this).unbind().click(function(){ $(this).siblings('.the-tagcloud').toggle(); return false; }); return false; }); } }; commentsBox = { st : 0, get : function(total, num) { var st = this.st, data; if ( ! num ) num = 20; this.st += num; this.total = total; $('#commentsdiv img.waiting').show(); data = { 'action' : 'get-comments', 'mode' : 'single', '_ajax_nonce' : $('#add_comment_nonce').val(), 'p' : $('#post_ID').val(), 'start' : st, 'number' : num }; $.post(ajaxurl, data, function(r) { r = wpAjax.parseAjaxResponse(r); $('#commentsdiv .widefat').show(); $('#commentsdiv img.waiting').hide(); if ( 'object' == typeof r && r.responses[0] ) { $('#the-comment-list').append( r.responses[0].data ); theList = theExtraList = null; $("a[className*=':']").unbind(); if ( commentsBox.st > commentsBox.total ) $('#show-comments').hide(); else $('#show-comments').show().children('a').html(postL10n.showcomm); return; } else if ( 1 == r ) { $('#show-comments').html(postL10n.endcomm); return; } $('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>'); } ); return false; } }; WPSetThumbnailHTML = function(html){ $('.inside', '#postimagediv').html(html); }; WPSetThumbnailID = function(id){ var field = $('input[value="_thumbnail_id"]', '#list-table'); if ( field.size() > 0 ) { $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id); } }; WPRemoveThumbnail = function(nonce){ $.post(ajaxurl, { action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie) }, function(str){ if ( str == '0' ) { alert( setPostThumbnailL10n.error ); } else { WPSetThumbnailHTML(str); } } ); }; })(jQuery); jQuery(document).ready( function($) { var stamp, visibility, sticky = '', last = 0, co = $('#content'); postboxes.add_postbox_toggles(pagenow); // multi-taxonomies if ( $('#tagsdiv-post_tag').length ) { tagBox.init(); } else { $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){ if ( this.id.indexOf('tagsdiv-') === 0 ) { tagBox.init(); return false; } }); } // categories $('.categorydiv').each( function(){ var this_id = $(this).attr('id'), noSyncChecks = false, syncChecks, catAddAfter, taxonomyParts, taxonomy, settingName; taxonomyParts = this_id.split('-'); taxonomyParts.shift(); taxonomy = taxonomyParts.join('-'); settingName = taxonomy + '_tab'; if ( taxonomy == 'category' ) settingName = 'cats'; // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.dev.js $('a', '#' + taxonomy + '-tabs').click( function(){ var t = $(this).attr('href'); $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide(); $(t).show(); if ( '#' + taxonomy + '-all' == t ) deleteUserSetting(settingName); else setUserSetting(settingName, 'pop'); return false; }); if ( getUserSetting(settingName) ) $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click(); // Ajax Cat $('#new' + taxonomy).one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } ); $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); }); syncChecks = function() { if ( noSyncChecks ) return; noSyncChecks = true; var th = jQuery(this), c = th.is(':checked'), id = th.val().toString(); $('#in-' + taxonomy + '-' + id + ', #in-' + taxonomy + '-category-' + id).prop( 'checked', c ); noSyncChecks = false; }; catAddBefore = function( s ) { if ( !$('#new'+taxonomy).val() ) return false; s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize(); $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true ); return s; }; catAddAfter = function( r, s ) { var sup, drop = $('#new'+taxonomy+'_parent'); $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false ); if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) { drop.before(sup); drop.remove(); } }; $('#' + taxonomy + 'checklist').wpList({ alt: '', response: taxonomy + '-ajax-response', addBefore: catAddBefore, addAfter: catAddAfter }); $('#' + taxonomy + '-add-toggle').click( function() { $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' ); $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click(); $('#new'+taxonomy).focus(); return false; }); $('#' + taxonomy + 'checklist li.popular-category :checkbox, #' + taxonomy + 'checklist-pop :checkbox').live( 'click', function(){ var t = $(this), c = t.is(':checked'), id = t.val(); if ( id && t.parents('#taxonomy-'+taxonomy).length ) $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c ); }); }); // end cats // Custom Fields if ( $('#postcustom').length ) { $('#the-list').wpList( { addAfter: function( xml, s ) { $('table#list-table').show(); }, addBefore: function( s ) { s.data += '&post_id=' + $('#post_ID').val(); return s; } }); } // submitdiv if ( $('#submitdiv').length ) { stamp = $('#timestamp').html(); visibility = $('#post-visibility-display').html(); function updateVisibility() { var pvSelect = $('#post-visibility-select'); if ( $('input:radio:checked', pvSelect).val() != 'public' ) { $('#sticky').prop('checked', false); $('#sticky-span').hide(); } else { $('#sticky-span').show(); } if ( $('input:radio:checked', pvSelect).val() != 'password' ) { $('#password-span').hide(); } else { $('#password-span').show(); } } function updateText() { var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'), optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(); attemptedDate = new Date( aa, mm - 1, jj, hh, mn ); originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() ); currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() ); if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) { $('.timestamp-wrap', '#timestampdiv').addClass('form-invalid'); return false; } else { $('.timestamp-wrap', '#timestampdiv').removeClass('form-invalid'); } if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) { publishOn = postL10n.publishOnFuture; $('#publish').val( postL10n.schedule ); } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) { publishOn = postL10n.publishOn; $('#publish').val( postL10n.publish ); } else { publishOn = postL10n.publishOnPast; $('#publish').val( postL10n.update ); } if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack $('#timestamp').html(stamp); } else { $('#timestamp').html( publishOn + ' <b>' + $('option[value="' + $('#mm').val() + '"]', '#mm').text() + ' ' + jj + ', ' + aa + ' @ ' + hh + ':' + mn + '</b> ' ); } if ( $('input:radio:checked', '#post-visibility-select').val() == 'private' ) { $('#publish').val( postL10n.update ); if ( optPublish.length == 0 ) { postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>'); } else { optPublish.html( postL10n.privatelyPublished ); } $('option[value="publish"]', postStatus).prop('selected', true); $('.edit-post-status', '#misc-publishing-actions').hide(); } else { if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) { if ( optPublish.length ) { optPublish.remove(); postStatus.val($('#hidden_post_status').val()); } } else { optPublish.html( postL10n.published ); } if ( postStatus.is(':hidden') ) $('.edit-post-status', '#misc-publishing-actions').show(); } $('#post-status-display').html($('option:selected', postStatus).text()); if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) { $('#save-post').hide(); } else { $('#save-post').show(); if ( $('option:selected', postStatus).val() == 'pending' ) { $('#save-post').show().val( postL10n.savePending ); } else { $('#save-post').show().val( postL10n.saveDraft ); } } return true; } $('.edit-visibility', '#visibility').click(function () { if ($('#post-visibility-select').is(":hidden")) { updateVisibility(); $('#post-visibility-select').slideDown('fast'); $(this).hide(); } return false; }); $('.cancel-post-visibility', '#post-visibility-select').click(function () { $('#post-visibility-select').slideUp('fast'); $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true); $('#post_password').val($('#hidden_post_password').val()); $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked')); $('#post-visibility-display').html(visibility); $('.edit-visibility', '#visibility').show(); updateText(); return false; }); $('.save-post-visibility', '#post-visibility-select').click(function () { // crazyhorse - multiple ok cancels var pvSelect = $('#post-visibility-select'); pvSelect.slideUp('fast'); $('.edit-visibility', '#visibility').show(); updateText(); if ( $('input:radio:checked', pvSelect).val() != 'public' ) { $('#sticky').prop('checked', false); } // WEAPON LOCKED if ( true == $('#sticky').prop('checked') ) { sticky = 'Sticky'; } else { sticky = ''; } $('#post-visibility-display').html( postL10n[$('input:radio:checked', pvSelect).val() + sticky] ); return false; }); $('input:radio', '#post-visibility-select').change(function() { updateVisibility(); }); $('#timestampdiv').siblings('a.edit-timestamp').click(function() { if ($('#timestampdiv').is(":hidden")) { $('#timestampdiv').slideDown('fast'); $(this).hide(); } return false; }); $('.cancel-timestamp', '#timestampdiv').click(function() { $('#timestampdiv').slideUp('fast'); $('#mm').val($('#hidden_mm').val()); $('#jj').val($('#hidden_jj').val()); $('#aa').val($('#hidden_aa').val()); $('#hh').val($('#hidden_hh').val()); $('#mn').val($('#hidden_mn').val()); $('#timestampdiv').siblings('a.edit-timestamp').show(); updateText(); return false; }); $('.save-timestamp', '#timestampdiv').click(function () { // crazyhorse - multiple ok cancels if ( updateText() ) { $('#timestampdiv').slideUp('fast'); $('#timestampdiv').siblings('a.edit-timestamp').show(); } return false; }); $('#post-status-select').siblings('a.edit-post-status').click(function() { if ($('#post-status-select').is(":hidden")) { $('#post-status-select').slideDown('fast'); $(this).hide(); } return false; }); $('.save-post-status', '#post-status-select').click(function() { $('#post-status-select').slideUp('fast'); $('#post-status-select').siblings('a.edit-post-status').show(); updateText(); return false; }); $('.cancel-post-status', '#post-status-select').click(function() { $('#post-status-select').slideUp('fast'); $('#post_status').val($('#hidden_post_status').val()); $('#post-status-select').siblings('a.edit-post-status').show(); updateText(); return false; }); } // end submitdiv // permalink if ( $('#edit-slug-box').length ) { editPermalink = function(post_id) { var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.val(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html(); $('#view-post-btn').hide(); b.html('<a href="#" class="save button">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>'); b.children('.save').click(function() { var new_slug = e.children('input').val(); if ( new_slug == $('#editable-post-name-full').text() ) { return $('.cancel', '#edit-slug-buttons').click(); } $.post(ajaxurl, { action: 'sample-permalink', post_id: post_id, new_slug: new_slug, new_title: $('#title').val(), samplepermalinknonce: $('#samplepermalinknonce').val() }, function(data) { $('#edit-slug-box').html(data); b.html(revert_b); real_slug.val(new_slug); makeSlugeditClickable(); $('#view-post-btn').show(); }); return false; }); $('.cancel', '#edit-slug-buttons').click(function() { $('#view-post-btn').show(); e.html(revert_e); b.html(revert_b); real_slug.val(revert_slug); return false; }); for ( i = 0; i < full.length; ++i ) { if ( '%' == full.charAt(i) ) c++; } slug_value = ( c > full.length / 4 ) ? '' : full; e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){ var key = e.keyCode || 0; // on enter, just save the new slug, don't save the post if ( 13 == key ) { b.children('.save').click(); return false; } if ( 27 == key ) { b.children('.cancel').click(); return false; } real_slug.val(this.value); }).focus(); } makeSlugeditClickable = function() { $('#editable-post-name').click(function() { $('#edit-slug-buttons').children('.edit-slug').click(); }); } makeSlugeditClickable(); } // word count if ( typeof(wpWordCount) != 'undefined' ) { $(document).triggerHandler('wpcountwords', [ co.val() ]); co.keyup( function(e) { var k = e.keyCode || e.charCode; if ( k == last ) return true; if ( 13 == k || 8 == last || 46 == last ) $(document).triggerHandler('wpcountwords', [ co.val() ]); last = k; return true; }); } wptitlehint = function(id) { id = id || 'title'; var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text'); if ( title.val() == '' ) titleprompt.css('visibility', ''); titleprompt.click(function(){ $(this).css('visibility', 'hidden'); title.focus(); }); title.blur(function(){ if ( this.value == '' ) titleprompt.css('visibility', ''); }).focus(function(){ titleprompt.css('visibility', 'hidden'); }).keydown(function(e){ titleprompt.css('visibility', 'hidden'); $(this).unbind(e); }); } wptitlehint(); });
01happy-blog
trunk/myblog/wp-admin/js/post.dev.js
JavaScript
oos
19,510
// utility functions var wpCookies = { // The following functions are from Cookie.js class in TinyMCE, Moxiecode, used under LGPL. each : function(obj, cb, scope) { var n, l; if ( !obj ) return 0; scope = scope || obj; if ( typeof(obj.length) != 'undefined' ) { for ( n = 0, l = obj.length; n < l; n++ ) { if ( cb.call(scope, obj[n], n, obj) === false ) return 0; } } else { for ( n in obj ) { if ( obj.hasOwnProperty(n) ) { if ( cb.call(scope, obj[n], n, obj) === false ) { return 0; } } } } return 1; }, /** * Get a multi-values cookie. * Returns a JS object with the name: 'value' pairs. */ getHash : function(name) { var all = this.get(name), ret; if ( all ) { this.each( all.split('&'), function(pair) { pair = pair.split('='); ret = ret || {}; ret[pair[0]] = pair[1]; }); } return ret; }, /** * Set a multi-values cookie. * * 'values_obj' is the JS object that is stored. It is encoded as URI in wpCookies.set(). */ setHash : function(name, values_obj, expires, path, domain, secure) { var str = ''; this.each(values_obj, function(val, key) { str += (!str ? '' : '&') + key + '=' + val; }); this.set(name, str, expires, path, domain, secure); }, /** * Get a cookie. */ get : function(name) { var cookie = document.cookie, e, p = name + "=", b; if ( !cookie ) return; b = cookie.indexOf("; " + p); if ( b == -1 ) { b = cookie.indexOf(p); if ( b != 0 ) return null; } else { b += 2; } e = cookie.indexOf(";", b); if ( e == -1 ) e = cookie.length; return decodeURIComponent( cookie.substring(b + p.length, e) ); }, /** * Set a cookie. * * The 'expires' arg can be either a JS Date() object set to the expiration date (back-compat) * or the number of seconds until expiration */ set : function(name, value, expires, path, domain, secure) { var d = new Date(); if ( typeof(expires) == 'object' && expires.toGMTString ) { expires = expires.toGMTString(); } else if ( parseInt(expires, 10) ) { d.setTime( d.getTime() + ( parseInt(expires, 10) * 1000 ) ); // time must be in miliseconds expires = d.toGMTString(); } else { expires = ''; } document.cookie = name + "=" + encodeURIComponent(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); }, /** * Remove a cookie. * * This is done by setting it to an empty value and setting the expiration time in the past. */ remove : function(name, path) { this.set(name, '', -1000, path); } }; // Returns the value as string. Second arg or empty string is returned when value is not set. function getUserSetting( name, def ) { var obj = getAllUserSettings(); if ( obj.hasOwnProperty(name) ) return obj[name]; if ( typeof def != 'undefined' ) return def; return ''; } // Both name and value must be only ASCII letters, numbers or underscore // and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text. function setUserSetting( name, value, _del ) { if ( 'object' !== typeof userSettings ) return false; var cookie = 'wp-settings-' + userSettings.uid, all = wpCookies.getHash(cookie) || {}, path = userSettings.url, n = name.toString().replace(/[^A-Za-z0-9_]/, ''), v = value.toString().replace(/[^A-Za-z0-9_]/, ''); if ( _del ) { delete all[n]; } else { all[n] = v; } wpCookies.setHash(cookie, all, 31536000, path); wpCookies.set('wp-settings-time-'+userSettings.uid, userSettings.time, 31536000, path); return name; } function deleteUserSetting( name ) { return setUserSetting( name, '', 1 ); } // Returns all settings as js object. function getAllUserSettings() { if ( 'object' !== typeof userSettings ) return {}; return wpCookies.getHash('wp-settings-' + userSettings.uid) || {}; }
01happy-blog
trunk/myblog/wp-admin/js/utils.dev.js
JavaScript
oos
3,951
(function($){ function check_pass_strength() { var pass1 = $('#pass1').val(), user = $('#user_login').val(), pass2 = $('#pass2').val(), strength; $('#pass-strength-result').removeClass('short bad good strong'); if ( ! pass1 ) { $('#pass-strength-result').html( pwsL10n.empty ); return; } strength = passwordStrength(pass1, user, pass2); switch ( strength ) { case 2: $('#pass-strength-result').addClass('bad').html( pwsL10n['bad'] ); break; case 3: $('#pass-strength-result').addClass('good').html( pwsL10n['good'] ); break; case 4: $('#pass-strength-result').addClass('strong').html( pwsL10n['strong'] ); break; case 5: $('#pass-strength-result').addClass('short').html( pwsL10n['mismatch'] ); break; default: $('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); } } $(document).ready( function() { var select = $('#display_name'); $('#pass1').val('').keyup( check_pass_strength ); $('#pass2').val('').keyup( check_pass_strength ); $('#pass-strength-result').show(); $('.color-palette').click( function() { $(this).siblings('input[name="admin_color"]').prop('checked', true); }); if ( select.length ) { $('#first_name, #last_name, #nickname').bind( 'blur.user_profile', function() { var dub = [], inputs = { display_nickname : $('#nickname').val() || '', display_username : $('#user_login').val() || '', display_firstname : $('#first_name').val() || '', display_lastname : $('#last_name').val() || '' }; if ( inputs.display_firstname && inputs.display_lastname ) { inputs['display_firstlast'] = inputs.display_firstname + ' ' + inputs.display_lastname; inputs['display_lastfirst'] = inputs.display_lastname + ' ' + inputs.display_firstname; } $.each( $('option', select), function( i, el ){ dub.push( el.value ); }); $.each(inputs, function( id, value ) { if ( ! value ) return; var val = value.replace(/<\/?[a-z][^>]*>/gi, ''); if ( inputs[id].length && $.inArray( val, dub ) == -1 ) { dub.push(val); $('<option />', { 'text': val }).appendTo( select ); } }); }); } }); })(jQuery);
01happy-blog
trunk/myblog/wp-admin/js/user-profile.dev.js
JavaScript
oos
2,246
var wpWidgets; (function($) { wpWidgets = { init : function() { var rem, sidebars = $('div.widgets-sortables'), isRTL = !! ( 'undefined' != typeof isRtl && isRtl ), margin = ( isRtl ? 'marginRight' : 'marginLeft' ), the_id; $('#widgets-right').children('.widgets-holder-wrap').children('.sidebar-name').click(function(){ var c = $(this).siblings('.widgets-sortables'), p = $(this).parent(); if ( !p.hasClass('closed') ) { c.sortable('disable'); p.addClass('closed'); } else { p.removeClass('closed'); c.sortable('enable').sortable('refresh'); } }); $('#widgets-left').children('.widgets-holder-wrap').children('.sidebar-name').click(function() { $(this).parent().toggleClass('closed'); }); sidebars.each(function(){ if ( $(this).parent().hasClass('inactive') ) return true; var h = 50, H = $(this).children('.widget').length; h = h + parseInt(H * 48, 10); $(this).css( 'minHeight', h + 'px' ); }); $('a.widget-action').live('click', function(){ var css = {}, widget = $(this).closest('div.widget'), inside = widget.children('.widget-inside'), w = parseInt( widget.find('input.widget-width').val(), 10 ); if ( inside.is(':hidden') ) { if ( w > 250 && inside.closest('div.widgets-sortables').length ) { css['width'] = w + 30 + 'px'; if ( inside.closest('div.widget-liquid-right').length ) css[margin] = 235 - w + 'px'; widget.css(css); } wpWidgets.fixLabels(widget); inside.slideDown('fast'); } else { inside.slideUp('fast', function() { widget.css({'width':'', margin:''}); }); } return false; }); $('input.widget-control-save').live('click', function(){ wpWidgets.save( $(this).closest('div.widget'), 0, 1, 0 ); return false; }); $('a.widget-control-remove').live('click', function(){ wpWidgets.save( $(this).closest('div.widget'), 1, 1, 0 ); return false; }); $('a.widget-control-close').live('click', function(){ wpWidgets.close( $(this).closest('div.widget') ); return false; }); sidebars.children('.widget').each(function() { wpWidgets.appendTitle(this); if ( $('p.widget-error', this).length ) $('a.widget-action', this).click(); }); $('#widget-list').children('.widget').draggable({ connectToSortable: 'div.widgets-sortables', handle: '> .widget-top > .widget-title', distance: 2, helper: 'clone', zIndex: 5, containment: 'document', start: function(e,ui) { ui.helper.find('div.widget-description').hide(); the_id = this.id; }, stop: function(e,ui) { if ( rem ) $(rem).hide(); rem = ''; } }); sidebars.sortable({ placeholder: 'widget-placeholder', items: '> .widget', handle: '> .widget-top > .widget-title', cursor: 'move', distance: 2, containment: 'document', start: function(e,ui) { ui.item.children('.widget-inside').hide(); ui.item.css({margin:'', 'width':''}); }, stop: function(e,ui) { if ( ui.item.hasClass('ui-draggable') && ui.item.data('draggable') ) ui.item.draggable('destroy'); if ( ui.item.hasClass('deleting') ) { wpWidgets.save( ui.item, 1, 0, 1 ); // delete widget ui.item.remove(); return; } var add = ui.item.find('input.add_new').val(), n = ui.item.find('input.multi_number').val(), id = the_id, sb = $(this).attr('id'); ui.item.css({margin:'', 'width':''}); the_id = ''; if ( add ) { if ( 'multi' == add ) { ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__|%i%/g, n); }) ); ui.item.attr( 'id', id.replace('__i__', n) ); n++; $('div#' + id).find('input.multi_number').val(n); } else if ( 'single' == add ) { ui.item.attr( 'id', 'new-' + id ); rem = 'div#' + id; } wpWidgets.save( ui.item, 0, 0, 1 ); ui.item.find('input.add_new').val(''); ui.item.find('a.widget-action').click(); return; } wpWidgets.saveOrder(sb); }, receive: function(e, ui) { var sender = $(ui.sender); if ( !$(this).is(':visible') || this.id.indexOf('orphaned_widgets') != -1 ) sender.sortable('cancel'); if ( sender.attr('id').indexOf('orphaned_widgets') != -1 && !sender.children('.widget').length ) { sender.parents('.orphan-sidebar').slideUp(400, function(){ $(this).remove(); }); } } }).sortable('option', 'connectWith', 'div.widgets-sortables').parent().filter('.closed').children('.widgets-sortables').sortable('disable'); $('#available-widgets').droppable({ tolerance: 'pointer', accept: function(o){ return $(o).parent().attr('id') != 'widget-list'; }, drop: function(e,ui) { ui.draggable.addClass('deleting'); $('#removing-widget').hide().children('span').html(''); }, over: function(e,ui) { ui.draggable.addClass('deleting'); $('div.widget-placeholder').hide(); if ( ui.draggable.hasClass('ui-sortable-helper') ) $('#removing-widget').show().children('span') .html( ui.draggable.find('div.widget-title').children('h4').html() ); }, out: function(e,ui) { ui.draggable.removeClass('deleting'); $('div.widget-placeholder').show(); $('#removing-widget').hide().children('span').html(''); } }); }, saveOrder : function(sb) { if ( sb ) $('#' + sb).closest('div.widgets-holder-wrap').find('img.ajax-feedback').css('visibility', 'visible'); var a = { action: 'widgets-order', savewidgets: $('#_wpnonce_widgets').val(), sidebars: [] }; $('div.widgets-sortables').each( function() { if ( $(this).sortable ) a['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(','); }); $.post( ajaxurl, a, function() { $('img.ajax-feedback').css('visibility', 'hidden'); }); this.resize(); }, save : function(widget, del, animate, order) { var sb = widget.closest('div.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a; widget = $(widget); $('.ajax-feedback', widget).css('visibility', 'visible'); a = { action: 'save-widget', savewidgets: $('#_wpnonce_widgets').val(), sidebar: sb }; if ( del ) a['delete_widget'] = 1; data += '&' + $.param(a); $.post( ajaxurl, data, function(r){ var id; if ( del ) { if ( !$('input.widget_number', widget).val() ) { id = $('input.widget-id', widget).val(); $('#available-widgets').find('input.widget-id').each(function(){ if ( $(this).val() == id ) $(this).closest('div.widget').show(); }); } if ( animate ) { order = 0; widget.slideUp('fast', function(){ $(this).remove(); wpWidgets.saveOrder(); }); } else { widget.remove(); wpWidgets.resize(); } } else { $('.ajax-feedback').css('visibility', 'hidden'); if ( r && r.length > 2 ) { $('div.widget-content', widget).html(r); wpWidgets.appendTitle(widget); wpWidgets.fixLabels(widget); } } if ( order ) wpWidgets.saveOrder(); }); }, appendTitle : function(widget) { var title = $('input[id*="-title"]', widget).val() || ''; if ( title ) title = ': ' + title.replace(/<[^<>]+>/g, '').replace(/</g, '&lt;').replace(/>/g, '&gt;'); $(widget).children('.widget-top').children('.widget-title').children() .children('.in-widget-title').html(title); }, resize : function() { $('div.widgets-sortables').each(function(){ if ( $(this).parent().hasClass('inactive') ) return true; var h = 50, H = $(this).children('.widget').length; h = h + parseInt(H * 48, 10); $(this).css( 'minHeight', h + 'px' ); }); }, fixLabels : function(widget) { widget.children('.widget-inside').find('label').each(function(){ var f = $(this).attr('for'); if ( f && f == $('input', this).attr('id') ) $(this).removeAttr('for'); }); }, close : function(widget) { widget.children('.widget-inside').slideUp('fast', function(){ widget.css({'width':'', margin:''}); }); } }; $(document).ready(function($){ wpWidgets.init(); }); })(jQuery);
01happy-blog
trunk/myblog/wp-admin/js/widgets.dev.js
JavaScript
oos
8,091
/* Plugin Browser Thickbox related JS*/ var tb_position; jQuery(document).ready(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(); }); $('#dashboard_plugins a.thickbox, .plugins a.thickbox').click( function() { tb_click.call(this); $('#TB_title').css({'background-color':'#222','color':'#cfcfcf'}); $('#TB_ajaxWindowTitle').html('<strong>' + plugininstallL10n.plugin_information + '</strong>&nbsp;' + $(this).attr('title') ); return false; }); /* Plugin install related JS*/ $('#plugin-information #sidemenu a').click( function() { var tab = $(this).attr('name'); //Flip the tab $('#plugin-information-header a.current').removeClass('current'); $(this).addClass('current'); //Flip the content. $('#section-holder div.section').hide(); //Hide 'em all $('#section-' + tab).show(); return false; }); $('a.install-now').click( function() { return confirm( plugininstallL10n.ays ); }); });
01happy-blog
trunk/myblog/wp-admin/js/plugin-install.dev.js
JavaScript
oos
1,865
(function( exports, $ ){ var api = wp.customize; /* * @param options * - previewer - The Previewer instance to sync with. * - transport - The transport to use for previewing. Supports 'refresh' and 'postMessage'. */ api.Setting = api.Value.extend({ initialize: function( id, value, options ) { var element; api.Value.prototype.initialize.call( this, value, options ); this.id = id; this.transport = this.transport || 'refresh'; this.bind( this.preview ); }, preview: function() { switch ( this.transport ) { case 'refresh': return this.previewer.refresh(); case 'postMessage': return this.previewer.send( 'setting', [ this.id, this() ] ); } } }); api.Control = api.Class.extend({ initialize: function( id, options ) { var control = this, nodes, radios, settings; this.params = {}; $.extend( this, options || {} ); this.id = id; this.selector = '#customize-control-' + id.replace( ']', '' ).replace( '[', '-' ); this.container = $( this.selector ); settings = $.map( this.params.settings, function( value ) { return value; }); api.apply( api, settings.concat( function() { var key; control.settings = {}; for ( key in control.params.settings ) { control.settings[ key ] = api( control.params.settings[ key ] ); } control.setting = control.settings['default'] || null; control.ready(); }) ); control.elements = []; nodes = this.container.find('[data-customize-setting-link]'); radios = {}; nodes.each( function() { var node = $(this), name; if ( node.is(':radio') ) { name = node.prop('name'); if ( radios[ name ] ) return; radios[ name ] = true; node = nodes.filter( '[name="' + name + '"]' ); } api( node.data('customizeSettingLink'), function( setting ) { var element = new api.Element( node ); control.elements.push( element ); element.sync( setting ); element.set( setting() ); }); }); }, ready: function() {}, dropdownInit: function() { var control = this, statuses = this.container.find('.dropdown-status'), params = this.params, update = function( to ) { if ( typeof to === 'string' && params.statuses && params.statuses[ to ] ) statuses.html( params.statuses[ to ] ).show(); else statuses.hide(); }; // Support the .dropdown class to open/close complex elements this.container.on( 'click', '.dropdown', function( event ) { event.preventDefault(); control.container.toggleClass('open'); }); this.setting.bind( update ); update( this.setting() ); } }); api.ColorControl = api.Control.extend({ ready: function() { var control = this, rhex, spot, input, text, update; rhex = /^#([A-Fa-f0-9]{3}){0,2}$/; spot = this.container.find('.dropdown-content'); input = new api.Element( this.container.find('.color-picker-hex') ); update = function( color ) { spot.css( 'background', color ); control.farbtastic.setColor( color ); }; this.farbtastic = $.farbtastic( this.container.find('.farbtastic-placeholder'), control.setting.set ); // Only pass through values that are valid hexes/empty. input.sync( this.setting ).validate = function( to ) { return rhex.test( to ) ? to : null; }; this.setting.bind( update ); update( this.setting() ); this.dropdownInit(); } }); api.UploadControl = api.Control.extend({ ready: function() { var control = this; this.params.removed = this.params.removed || ''; this.success = $.proxy( this.success, this ); this.uploader = $.extend({ container: this.container, browser: this.container.find('.upload'), dropzone: this.container.find('.upload-dropzone'), success: this.success }, this.uploader || {} ); if ( this.uploader.supported ) { if ( control.params.context ) control.uploader.param( 'post_data[context]', this.params.context ); control.uploader.param( 'post_data[theme]', api.settings.theme.stylesheet ); } this.uploader = new wp.Uploader( this.uploader ); this.remover = this.container.find('.remove'); this.remover.click( function( event ) { control.setting.set( control.params.removed ); event.preventDefault(); }); this.removerVisibility = $.proxy( this.removerVisibility, this ); this.setting.bind( this.removerVisibility ); this.removerVisibility( this.setting.get() ); }, success: function( attachment ) { this.setting.set( attachment.url ); }, removerVisibility: function( to ) { this.remover.toggle( to != this.params.removed ); } }); api.ImageControl = api.UploadControl.extend({ ready: function() { var control = this, panels; this.uploader = { init: function( up ) { var fallback, button; if ( this.supports.dragdrop ) return; // Maintain references while wrapping the fallback button. fallback = control.container.find( '.upload-fallback' ); button = fallback.children().detach(); this.browser.detach().empty().append( button ); fallback.append( this.browser ).show(); } }; api.UploadControl.prototype.ready.call( this ); this.thumbnail = this.container.find('.preview-thumbnail img'); this.thumbnailSrc = $.proxy( this.thumbnailSrc, this ); this.setting.bind( this.thumbnailSrc ); this.library = this.container.find('.library'); // Generate tab objects this.tabs = {}; panels = this.library.find('.library-content'); this.library.children('ul').children('li').each( function() { var link = $(this), id = link.data('customizeTab'), panel = panels.filter('[data-customize-tab="' + id + '"]'); control.tabs[ id ] = { both: link.add( panel ), link: link, panel: panel }; }); // Select a tab this.selected = this.tabs[ panels.first().data('customizeTab') ]; this.selected.both.addClass('library-selected'); // Bind tab switch events this.library.children('ul').on( 'click', 'li', function( event ) { var id = $(this).data('customizeTab'), tab = control.tabs[ id ]; event.preventDefault(); if ( tab.link.hasClass('library-selected') ) return; control.selected.both.removeClass('library-selected'); control.selected = tab; control.selected.both.addClass('library-selected'); }); // Bind events to switch image urls. this.library.on( 'click', 'a', function( event ) { var value = $(this).data('customizeImageValue'); if ( value ) { control.setting.set( value ); event.preventDefault(); } }); if ( this.tabs.uploaded ) { this.tabs.uploaded.target = this.library.find('.uploaded-target'); if ( ! this.tabs.uploaded.panel.find('.thumbnail').length ) this.tabs.uploaded.both.addClass('hidden'); } this.dropdownInit(); }, success: function( attachment ) { api.UploadControl.prototype.success.call( this, attachment ); // Add the uploaded image to the uploaded tab. if ( this.tabs.uploaded && this.tabs.uploaded.target.length ) { this.tabs.uploaded.both.removeClass('hidden'); attachment.element = $( '<a href="#" class="thumbnail"></a>' ) .data( 'customizeImageValue', attachment.url ) .append( '<img src="' + attachment.url+ '" />' ) .appendTo( this.tabs.uploaded.target ); } }, thumbnailSrc: function( to ) { if ( /^(https?:)?\/\//.test( to ) ) this.thumbnail.prop( 'src', to ).show(); else this.thumbnail.hide(); } }); // Change objects contained within the main customize object to Settings. api.defaultConstructor = api.Setting; // Create the collection of Control objects. api.control = new api.Values({ defaultConstructor: api.Control }); api.PreviewFrame = api.Messenger.extend({ sensitivity: 2000, initialize: function( params, options ) { var deferred = $.Deferred(), self = this; // This is the promise object. deferred.promise( this ); this.container = params.container; this.signature = params.signature; $.extend( params, { channel: api.PreviewFrame.uuid() }); api.Messenger.prototype.initialize.call( this, params, options ); this.add( 'previewUrl', params.previewUrl ); this.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() }); this.run( deferred ); }, run: function( deferred ) { var self = this, loaded = false, ready = false; if ( this._ready ) this.unbind( 'ready', this._ready ); this._ready = function() { ready = true; if ( loaded ) deferred.resolveWith( self ); }; this.bind( 'ready', this._ready ); this.request = $.ajax( this.previewUrl(), { type: 'POST', data: this.query, xhrFields: { withCredentials: true } } ); this.request.fail( function() { deferred.rejectWith( self, [ 'request failure' ] ); }); this.request.done( function( response ) { var location = self.request.getResponseHeader('Location'), signature = self.signature, index; // Check if the location response header differs from the current URL. // If so, the request was redirected; try loading the requested page. if ( location && location != self.previewUrl() ) { deferred.rejectWith( self, [ 'redirect', location ] ); return; } // Check if the user is not logged in. if ( '0' === response ) { self.login( deferred ); return; } // Check for cheaters. if ( '-1' === response ) { deferred.rejectWith( self, [ 'cheatin' ] ); return; } // Check for a signature in the request. index = response.lastIndexOf( signature ); if ( -1 === index || index < response.lastIndexOf('</html>') ) { deferred.rejectWith( self, [ 'unsigned' ] ); return; } // Strip the signature from the request. response = response.slice( 0, index ) + response.slice( index + signature.length ); // Create the iframe and inject the html content. self.iframe = $('<iframe />').appendTo( self.container ); // Bind load event after the iframe has been added to the page; // otherwise it will fire when injected into the DOM. self.iframe.one( 'load', function() { loaded = true; if ( ready ) { deferred.resolveWith( self ); } else { setTimeout( function() { deferred.rejectWith( self, [ 'ready timeout' ] ); }, self.sensitivity ); } }); self.targetWindow( self.iframe[0].contentWindow ); self.targetWindow().document.open(); self.targetWindow().document.write( response ); self.targetWindow().document.close(); }); }, login: function( deferred ) { var self = this, reject; reject = function() { deferred.rejectWith( self, [ 'logged out' ] ); }; if ( this.triedLogin ) return reject(); // Check if we have an admin cookie. $.get( api.settings.url.ajax, { action: 'logged-in' }).fail( reject ).done( function( response ) { var iframe; if ( '1' !== response ) reject(); iframe = $('<iframe src="' + self.previewUrl() + '" />').hide(); iframe.appendTo( self.container ); iframe.load( function() { self.triedLogin = true; iframe.remove(); self.run( deferred ); }); }); }, destroy: function() { api.Messenger.prototype.destroy.call( this ); this.request.abort(); if ( this.iframe ) this.iframe.remove(); delete this.request; delete this.iframe; delete this.targetWindow; } }); (function(){ var uuid = 0; api.PreviewFrame.uuid = function() { return 'preview-' + uuid++; }; }()); api.Previewer = api.Messenger.extend({ refreshBuffer: 250, /** * Requires params: * - container - a selector or jQuery element * - previewUrl - the URL of preview frame */ initialize: function( params, options ) { var self = this, rscheme = /^https?/, url; $.extend( this, options || {} ); /* * Wrap this.refresh to prevent it from hammering the servers: * * If refresh is called once and no other refresh requests are * loading, trigger the request immediately. * * If refresh is called while another refresh request is loading, * debounce the refresh requests: * 1. Stop the loading request (as it is instantly outdated). * 2. Trigger the new request once refresh hasn't been called for * self.refreshBuffer milliseconds. */ this.refresh = (function( self ) { var refresh = self.refresh, callback = function() { timeout = null; refresh.call( self ); }, timeout; return function() { if ( typeof timeout !== 'number' ) { if ( self.loading ) { self.abort(); } else { return callback(); } } clearTimeout( timeout ); timeout = setTimeout( callback, self.refreshBuffer ); }; })( this ); this.container = api.ensure( params.container ); this.allowedUrls = params.allowedUrls; this.signature = params.signature; params.url = window.location.href; api.Messenger.prototype.initialize.call( this, params ); this.add( 'scheme', this.origin() ).link( this.origin ).setter( function( to ) { var match = to.match( rscheme ); return match ? match[0] : ''; }); // Limit the URL to internal, front-end links. // // If the frontend and the admin are served from the same domain, load the // preview over ssl if the customizer is being loaded over ssl. This avoids // insecure content warnings. This is not attempted if the admin and frontend // are on different domains to avoid the case where the frontend doesn't have // ssl certs. this.add( 'previewUrl', params.previewUrl ).setter( function( to ) { var result; // Check for URLs that include "/wp-admin/" or end in "/wp-admin". // Strip hashes and query strings before testing. if ( /\/wp-admin(\/|$)/.test( to.replace(/[#?].*$/, '') ) ) return null; // Attempt to match the URL to the control frame's scheme // and check if it's allowed. If not, try the original URL. $.each([ to.replace( rscheme, self.scheme() ), to ], function( i, url ) { $.each( self.allowedUrls, function( i, allowed ) { if ( 0 === url.indexOf( allowed ) ) { result = url; return false; } }); if ( result ) return false; }); // If we found a matching result, return it. If not, bail. return result ? result : null; }); // Refresh the preview when the URL is changed (but not yet). this.previewUrl.bind( this.refresh ); this.scroll = 0; this.bind( 'scroll', function( distance ) { this.scroll = distance; }); // Update the URL when the iframe sends a URL message. this.bind( 'url', this.previewUrl ); }, query: function() {}, abort: function() { if ( this.loading ) { this.loading.destroy(); delete this.loading; } }, refresh: function() { var self = this; this.abort(); this.loading = new api.PreviewFrame({ url: this.url(), previewUrl: this.previewUrl(), query: this.query() || {}, container: this.container, signature: this.signature }); this.loading.done( function() { // 'this' is the loading frame this.bind( 'synced', function() { if ( self.preview ) self.preview.destroy(); self.preview = this; delete self.loading; self.targetWindow( this.targetWindow() ); self.channel( this.channel() ); self.send( 'active' ); }); this.send( 'sync', { scroll: self.scroll, settings: api.get() }); }); this.loading.fail( function( reason, location ) { if ( 'redirect' === reason && location ) self.previewUrl( location ); if ( 'logged out' === reason ) { if ( self.preview ) { self.preview.destroy(); delete self.preview; } self.login().done( self.refresh ); } if ( 'cheatin' === reason ) self.cheatin(); }); }, login: function() { var previewer = this, deferred, messenger, iframe; if ( this._login ) return this._login; deferred = $.Deferred(); this._login = deferred.promise(); messenger = new api.Messenger({ channel: 'login', url: api.settings.url.login }); iframe = $('<iframe src="' + api.settings.url.login + '" />').appendTo( this.container ); messenger.targetWindow( iframe[0].contentWindow ); messenger.bind( 'login', function() { iframe.remove(); messenger.destroy(); delete previewer._login; deferred.resolve(); }); return this._login; }, cheatin: function() { $( document.body ).empty().addClass('cheatin').append( '<p>' + api.l10n.cheatin + '</p>' ); } }); /* ===================================================================== * Ready. * ===================================================================== */ api.controlConstructor = { color: api.ColorControl, upload: api.UploadControl, image: api.ImageControl }; $( function() { api.settings = window._wpCustomizeSettings; api.l10n = window._wpCustomizeControlsL10n; // Check if we can run the customizer. if ( ! api.settings ) return; // Redirect to the fallback preview if any incompatibilities are found. if ( ! $.support.postMessage || ( ! $.support.cors && api.settings.isCrossDomain ) ) return window.location = api.settings.url.fallback; var body = $( document.body ), overlay = body.children('.wp-full-overlay'), query, previewer, parent; // Prevent the form from saving when enter is pressed. $('#customize-controls').on( 'keydown', function( e ) { if ( $( e.target ).is('textarea') ) return; if ( 13 === e.which ) // Enter e.preventDefault(); }); // Initialize Previewer previewer = new api.Previewer({ container: '#customize-preview', form: '#customize-controls', previewUrl: api.settings.url.preview, allowedUrls: api.settings.url.allowed, signature: 'WP_CUSTOMIZER_SIGNATURE' }, { nonce: api.settings.nonce, query: function() { return { wp_customize: 'on', theme: api.settings.theme.stylesheet, customized: JSON.stringify( api.get() ), nonce: this.nonce.preview }; }, save: function() { var self = this, query = $.extend( this.query(), { action: 'customize_save', nonce: this.nonce.save }), request = $.post( api.settings.url.ajax, query ); api.trigger( 'save', request ); body.addClass('saving'); request.always( function() { body.removeClass('saving'); }); request.done( function( response ) { // Check if the user is logged out. if ( '0' === response ) { self.preview.iframe.hide(); self.login().done( function() { self.save(); self.preview.iframe.show(); }); return; } // Check for cheaters. if ( '-1' === response ) { self.cheatin(); return; } api.trigger( 'saved' ); }); } }); // Refresh the nonces if the preview sends updated nonces over. previewer.bind( 'nonce', function( nonce ) { $.extend( this.nonce, nonce ); }); $.each( api.settings.settings, function( id, data ) { api.create( id, id, data.value, { transport: data.transport, previewer: previewer } ); }); $.each( api.settings.controls, function( id, data ) { var constructor = api.controlConstructor[ data.type ] || api.Control, control; control = api.control.add( id, new constructor( id, { params: data, previewer: previewer } ) ); }); // Check if preview url is valid and load the preview frame. if ( previewer.previewUrl() ) previewer.refresh(); else previewer.previewUrl( api.settings.url.home ); // Save and activated states (function() { var state = new api.Values(), saved = state.create('saved'), activated = state.create('activated'); state.bind( 'change', function() { var save = $('#save'), back = $('.back'); if ( ! activated() ) { save.val( api.l10n.activate ).prop( 'disabled', false ); back.text( api.l10n.cancel ); } else if ( saved() ) { save.val( api.l10n.saved ).prop( 'disabled', true ); back.text( api.l10n.close ); } else { save.val( api.l10n.save ).prop( 'disabled', false ); back.text( api.l10n.cancel ); } }); // Set default states. saved( true ); activated( api.settings.theme.active ); api.bind( 'change', function() { state('saved').set( false ); }); api.bind( 'saved', function() { state('saved').set( true ); state('activated').set( true ); }); activated.bind( function( to ) { if ( to ) api.trigger( 'activated' ); }); // Expose states to the API. api.state = state; }()); // Temporary accordion code. $('.customize-section-title').click( function( event ) { var clicked = $( this ).parents( '.customize-section' ); if ( clicked.hasClass('cannot-expand') ) return; $( '.customize-section' ).not( clicked ).removeClass( 'open' ); clicked.toggleClass( 'open' ); event.preventDefault(); }); // Button bindings. $('#save').click( function( event ) { previewer.save(); event.preventDefault(); }); $('.collapse-sidebar').click( function( event ) { overlay.toggleClass( 'collapsed' ).toggleClass( 'expanded' ); event.preventDefault(); }); // Create a potential postMessage connection with the parent frame. parent = new api.Messenger({ url: api.settings.url.parent, channel: 'loader' }); // If we receive a 'back' event, we're inside an iframe. // Send any clicks to the 'Return' link to the parent page. parent.bind( 'back', function() { $('.back').on( 'click.back', function( event ) { event.preventDefault(); parent.send( 'close' ); }); }); // Pass events through to the parent. api.bind( 'saved', function() { parent.send( 'saved' ); }); // When activated, let the loader handle redirecting the page. // If no loader exists, redirect the page ourselves (if a url exists). api.bind( 'activated', function() { if ( parent.targetWindow() ) parent.send( 'activated', api.settings.url.activated ); else if ( api.settings.url.activated ) window.location = api.settings.url.activated; }); // Initialize the connection with the parent frame. parent.send( 'ready' ); // Control visibility for default controls $.each({ 'background_image': { controls: [ 'background_repeat', 'background_position_x', 'background_attachment' ], callback: function( to ) { return !! to } }, 'show_on_front': { controls: [ 'page_on_front', 'page_for_posts' ], callback: function( to ) { return 'page' === to } }, 'header_textcolor': { controls: [ 'header_textcolor' ], callback: function( to ) { return 'blank' !== to } } }, function( settingId, o ) { api( settingId, function( setting ) { $.each( o.controls, function( i, controlId ) { api.control( controlId, function( control ) { var visibility = function( to ) { control.container.toggle( o.callback( to ) ); }; visibility( setting.get() ); setting.bind( visibility ); }); }); }); }); // Juggle the two controls that use header_textcolor api.control( 'display_header_text', function( control ) { var last = ''; control.elements[0].unsync( api( 'header_textcolor' ) ); control.element = new api.Element( control.container.find('input') ); control.element.set( 'blank' !== control.setting() ); control.element.bind( function( to ) { if ( ! to ) last = api( 'header_textcolor' ).get(); control.setting.set( to ? last : 'blank' ); }); control.setting.bind( function( to ) { control.element.set( 'blank' !== to ); }); }); // Handle header image data api.control( 'header_image', function( control ) { control.setting.bind( function( to ) { if ( to === control.params.removed ) control.settings.data.set( false ); }); control.library.on( 'click', 'a', function( event ) { control.settings.data.set( $(this).data('customizeHeaderImageData') ); }); control.uploader.success = function( attachment ) { var data; api.ImageControl.prototype.success.call( control, attachment ); data = { attachment_id: attachment.id, url: attachment.url, thumbnail_url: attachment.url, height: attachment.meta.height, width: attachment.meta.width }; attachment.element.data( 'customizeHeaderImageData', data ); control.settings.data.set( data ); } }); api.trigger( 'ready' ); }); })( wp, jQuery );
01happy-blog
trunk/myblog/wp-admin/js/customize-controls.dev.js
JavaScript
oos
24,948
// Password strength meter function passwordStrength(password1, username, password2) { var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, mismatch = 5, symbolSize = 0, natLog, score; // password 1 != password 2 if ( (password1 != password2) && password2.length > 0) return mismatch //password < 4 if ( password1.length < 4 ) return shortPass //password1 == username if ( password1.toLowerCase() == username.toLowerCase() ) return badPass; if ( password1.match(/[0-9]/) ) symbolSize +=10; if ( password1.match(/[a-z]/) ) symbolSize +=26; if ( password1.match(/[A-Z]/) ) symbolSize +=26; if ( password1.match(/[^a-zA-Z0-9]/) ) symbolSize +=31; natLog = Math.log( Math.pow(symbolSize, password1.length) ); score = natLog / Math.LN2; if (score < 40 ) return badPass if (score < 56 ) return goodPass return strongPass; }
01happy-blog
trunk/myblog/wp-admin/js/password-strength-meter.dev.js
JavaScript
oos
872
var imageEdit; (function($) { imageEdit = { iasapi : {}, hold : {}, postid : '', intval : function(f) { return f | 0; }, setDisabled : function(el, s) { if ( s ) { el.removeClass('disabled'); $('input', el).removeAttr('disabled'); } else { el.addClass('disabled'); $('input', el).prop('disabled', true); } }, init : function(postid, nonce) { var t = this, old = $('#image-editor-' + t.postid), x = t.intval( $('#imgedit-x-' + postid).val() ), y = t.intval( $('#imgedit-y-' + postid).val() ); if ( t.postid != postid && old.length ) t.close(t.postid); t.hold['w'] = t.hold['ow'] = x; t.hold['h'] = t.hold['oh'] = y; t.hold['xy_ratio'] = x / y; t.hold['sizer'] = parseFloat( $('#imgedit-sizer-' + postid).val() ); t.postid = postid; $('#imgedit-response-' + postid).empty(); $('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) { var k = e.keyCode; if ( 36 < k && k < 41 ) $(this).blur() if ( 13 == k ) { e.preventDefault(); e.stopPropagation(); return false; } }); }, toggleEditor : function(postid, toggle) { var wait = $('#imgedit-wait-' + postid); if ( toggle ) wait.height( $('#imgedit-panel-' + postid).height() ).fadeIn('fast'); else wait.fadeOut('fast'); }, toggleHelp : function(el) { $(el).siblings('.imgedit-help').slideToggle('fast'); return false; }, getTarget : function(postid) { return $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).val() || 'full'; }, scaleChanged : function(postid, x) { var w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid), warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = ''; if ( x ) { h1 = (w.val() != '') ? this.intval( w.val() / this.hold['xy_ratio'] ) : ''; h.val( h1 ); } else { w1 = (h.val() != '') ? this.intval( h.val() * this.hold['xy_ratio'] ) : ''; w.val( w1 ); } if ( ( h1 && h1 > this.hold['oh'] ) || ( w1 && w1 > this.hold['ow'] ) ) warn.css('visibility', 'visible'); else warn.css('visibility', 'hidden'); }, getSelRatio : function(postid) { var x = this.hold['w'], y = this.hold['h'], X = this.intval( $('#imgedit-crop-width-' + postid).val() ), Y = this.intval( $('#imgedit-crop-height-' + postid).val() ); if ( X && Y ) return X + ':' + Y; if ( x && y ) return x + ':' + y; return '1:1'; }, filterHistory : function(postid, setSize) { // apply undo state to history var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = []; if ( history != '' ) { history = JSON.parse(history); pop = this.intval( $('#imgedit-undone-' + postid).val() ); if ( pop > 0 ) { while ( pop > 0 ) { history.pop(); pop--; } } if ( setSize ) { if ( !history.length ) { this.hold['w'] = this.hold['ow']; this.hold['h'] = this.hold['oh']; return ''; } // restore o = history[history.length - 1]; o = o.c || o.r || o.f || false; if ( o ) { this.hold['w'] = o.fw; this.hold['h'] = o.fh; } } // filter the values for ( n in history ) { i = history[n]; if ( i.hasOwnProperty('c') ) { op[n] = { 'c': { 'x': i.c.x, 'y': i.c.y, 'w': i.c.w, 'h': i.c.h } }; } else if ( i.hasOwnProperty('r') ) { op[n] = { 'r': i.r.r }; } else if ( i.hasOwnProperty('f') ) { op[n] = { 'f': i.f.f }; } } return JSON.stringify(op); } return ''; }, refreshEditor : function(postid, nonce, callback) { var t = this, data, img; t.toggleEditor(postid, 1); data = { 'action': 'imgedit-preview', '_ajax_nonce': nonce, 'postid': postid, 'history': t.filterHistory(postid, 1), 'rand': t.intval(Math.random() * 1000000) }; img = $('<img id="image-preview-' + postid + '" />'); img.load( function() { var max1, max2, parent = $('#imgedit-crop-' + postid), t = imageEdit; parent.empty().append(img); // w, h are the new full size dims max1 = Math.max( t.hold.w, t.hold.h ); max2 = Math.max( $(img).width(), $(img).height() ); t.hold['sizer'] = max1 > max2 ? max2 / max1 : 1; t.initCrop(postid, img, parent); t.setCropSelection(postid, 0); if ( (typeof callback != "unknown") && callback != null ) callback(); if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() == 0 ) $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled'); else $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true); t.toggleEditor(postid, 0); }).error(function(){ $('#imgedit-crop-' + postid).empty().append('<div class="error"><p>' + imageEditL10n.error + '</p></div>'); t.toggleEditor(postid, 0); }).attr('src', ajaxurl + '?' + $.param(data)); }, action : function(postid, nonce, action) { var t = this, data, w, h, fw, fh; if ( t.notsaved(postid) ) return false; data = { 'action': 'image-editor', '_ajax_nonce': nonce, 'postid': postid }; if ( 'scale' == action ) { w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid), fw = t.intval(w.val()), fh = t.intval(h.val()); if ( fw < 1 ) { w.focus(); return false; } else if ( fh < 1 ) { h.focus(); return false; } if ( fw == t.hold.ow || fh == t.hold.oh ) return false; data['do'] = 'scale'; data['fwidth'] = fw; data['fheight'] = fh; } else if ( 'restore' == action ) { data['do'] = 'restore'; } else { return false; } t.toggleEditor(postid, 1); $.post(ajaxurl, data, function(r) { $('#image-editor-' + postid).empty().append(r); t.toggleEditor(postid, 0); }); }, save : function(postid, nonce) { var data, target = this.getTarget(postid), history = this.filterHistory(postid, 0); if ( '' == history ) return false; this.toggleEditor(postid, 1); data = { 'action': 'image-editor', '_ajax_nonce': nonce, 'postid': postid, 'history': history, 'target': target, 'do': 'save' }; $.post(ajaxurl, data, function(r) { var ret = JSON.parse(r); if ( ret.error ) { $('#imgedit-response-' + postid).html('<div class="error"><p>' + ret.error + '</p><div>'); imageEdit.close(postid); return; } if ( ret.fw && ret.fh ) $('#media-dims-' + postid).html( ret.fw + ' &times; ' + ret.fh ); if ( ret.thumbnail ) $('.thumbnail', '#thumbnail-head-' + postid).attr('src', ''+ret.thumbnail); if ( ret.msg ) $('#imgedit-response-' + postid).html('<div class="updated"><p>' + ret.msg + '</p></div>'); imageEdit.close(postid); }); }, open : function(postid, nonce) { var data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid), btn = $('#imgedit-open-btn-' + postid), spin = btn.siblings('img'); btn.prop('disabled', true); spin.css('visibility', 'visible'); data = { 'action': 'image-editor', '_ajax_nonce': nonce, 'postid': postid, 'do': 'open' }; elem.load(ajaxurl, data, function() { elem.fadeIn('fast'); head.fadeOut('fast', function(){ btn.removeAttr('disabled'); spin.css('visibility', 'hidden'); }); }); }, imgLoaded : function(postid) { var img = $('#image-preview-' + postid), parent = $('#imgedit-crop-' + postid); this.initCrop(postid, img, parent); this.setCropSelection(postid, 0); this.toggleEditor(postid, 0); }, initCrop : function(postid, image, parent) { var t = this, selW = $('#imgedit-sel-width-' + postid), selH = $('#imgedit-sel-height-' + postid); t.iasapi = $(image).imgAreaSelect({ parent: parent, instance: true, handles: true, keys: true, minWidth: 3, minHeight: 3, onInit: function(img, c) { parent.children().mousedown(function(e){ var ratio = false, sel, defRatio; if ( e.shiftKey ) { sel = t.iasapi.getSelection(); defRatio = t.getSelRatio(postid); ratio = ( sel && sel.width && sel.height ) ? sel.width + ':' + sel.height : defRatio; } t.iasapi.setOptions({ aspectRatio: ratio }); }); }, onSelectStart: function(img, c) { imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1); }, onSelectEnd: function(img, c) { imageEdit.setCropSelection(postid, c); }, onSelectChange: function(img, c) { var sizer = imageEdit.hold.sizer; selW.val( imageEdit.round(c.width / sizer) ); selH.val( imageEdit.round(c.height / sizer) ); } }); }, setCropSelection : function(postid, c) { var sel, min = $('#imgedit-minthumb-' + postid).val() || '128:128', sizer = this.hold['sizer']; min = min.split(':'); c = c || 0; if ( !c || ( c.width < 3 && c.height < 3 ) ) { this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0); this.setDisabled($('#imgedit-crop-sel-' + postid), 0); $('#imgedit-sel-width-' + postid).val(''); $('#imgedit-sel-height-' + postid).val(''); $('#imgedit-selection-' + postid).val(''); return false; } if ( c.width < (min[0] * sizer) && c.height < (min[1] * sizer) ) { this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0); $('#imgedit-selection-' + postid).val(''); return false; } sel = { 'x': c.x1, 'y': c.y1, 'w': c.width, 'h': c.height }; this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 1); $('#imgedit-selection-' + postid).val( JSON.stringify(sel) ); }, close : function(postid, warn) { warn = warn || false; if ( warn && this.notsaved(postid) ) return false; this.iasapi = {}; this.hold = {}; $('#image-editor-' + postid).fadeOut('fast', function() { $('#media-head-' + postid).fadeIn('fast'); $(this).empty(); }); }, notsaved : function(postid) { var h = $('#imgedit-history-' + postid).val(), history = (h != '') ? JSON.parse(h) : new Array(), pop = this.intval( $('#imgedit-undone-' + postid).val() ); if ( pop < history.length ) { if ( confirm( $('#imgedit-leaving-' + postid).html() ) ) return false; return true; } return false; }, addStep : function(op, postid, nonce) { var t = this, elem = $('#imgedit-history-' + postid), history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array(), undone = $('#imgedit-undone-' + postid), pop = t.intval(undone.val()); while ( pop > 0 ) { history.pop(); pop--; } undone.val(0); // reset history.push(op); elem.val( JSON.stringify(history) ); t.refreshEditor(postid, nonce, function() { t.setDisabled($('#image-undo-' + postid), true); t.setDisabled($('#image-redo-' + postid), false); }); }, rotate : function(angle, postid, nonce, t) { if ( $(t).hasClass('disabled') ) return false; this.addStep({ 'r': { 'r': angle, 'fw': this.hold['h'], 'fh': this.hold['w'] }}, postid, nonce); }, flip : function (axis, postid, nonce, t) { if ( $(t).hasClass('disabled') ) return false; this.addStep({ 'f': { 'f': axis, 'fw': this.hold['w'], 'fh': this.hold['h'] }}, postid, nonce); }, crop : function (postid, nonce, t) { var sel = $('#imgedit-selection-' + postid).val(), w = this.intval( $('#imgedit-sel-width-' + postid).val() ), h = this.intval( $('#imgedit-sel-height-' + postid).val() ); if ( $(t).hasClass('disabled') || sel == '' ) return false; sel = JSON.parse(sel); if ( sel.w > 0 && sel.h > 0 && w > 0 && h > 0 ) { sel['fw'] = w; sel['fh'] = h; this.addStep({ 'c': sel }, postid, nonce); } }, undo : function (postid, nonce) { var t = this, button = $('#image-undo-' + postid), elem = $('#imgedit-undone-' + postid), pop = t.intval( elem.val() ) + 1; if ( button.hasClass('disabled') ) return; elem.val(pop); t.refreshEditor(postid, nonce, function() { var elem = $('#imgedit-history-' + postid), history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array(); t.setDisabled($('#image-redo-' + postid), true); t.setDisabled(button, pop < history.length); }); }, redo : function(postid, nonce) { var t = this, button = $('#image-redo-' + postid), elem = $('#imgedit-undone-' + postid), pop = t.intval( elem.val() ) - 1; if ( button.hasClass('disabled') ) return; elem.val(pop); t.refreshEditor(postid, nonce, function() { t.setDisabled($('#image-undo-' + postid), true); t.setDisabled(button, pop > 0); }); }, setNumSelection : function(postid) { var sel, elX = $('#imgedit-sel-width-' + postid), elY = $('#imgedit-sel-height-' + postid), x = this.intval( elX.val() ), y = this.intval( elY.val() ), img = $('#image-preview-' + postid), imgh = img.height(), imgw = img.width(), sizer = this.hold['sizer'], x1, y1, x2, y2, ias = this.iasapi; if ( x < 1 ) { elX.val(''); return false; } if ( y < 1 ) { elY.val(''); return false; } if ( x && y && ( sel = ias.getSelection() ) ) { x2 = sel.x1 + Math.round( x * sizer ); y2 = sel.y1 + Math.round( y * sizer ); x1 = sel.x1; y1 = sel.y1; if ( x2 > imgw ) { x1 = 0; x2 = imgw; elX.val( Math.round( x2 / sizer ) ); } if ( y2 > imgh ) { y1 = 0; y2 = imgh; elY.val( Math.round( y2 / sizer ) ); } ias.setSelection( x1, y1, x2, y2 ); ias.update(); this.setCropSelection(postid, ias.getSelection()); } }, round : function(num) { var s; num = Math.round(num); if ( this.hold.sizer > 0.6 ) return num; s = num.toString().slice(-1); if ( '1' == s ) return num - 1; else if ( '9' == s ) return num + 1; return num; }, setRatioSelection : function(postid, n, el) { var sel, r, x = this.intval( $('#imgedit-crop-width-' + postid).val() ), y = this.intval( $('#imgedit-crop-height-' + postid).val() ), h = $('#image-preview-' + postid).height(); if ( !this.intval( $(el).val() ) ) { $(el).val(''); return; } if ( x && y ) { this.iasapi.setOptions({ aspectRatio: x + ':' + y }); if ( sel = this.iasapi.getSelection(true) ) { r = Math.ceil( sel.y1 + ((sel.x2 - sel.x1) / (x / y)) ); if ( r > h ) { r = h; if ( n ) $('#imgedit-crop-height-' + postid).val(''); else $('#imgedit-crop-width-' + postid).val(''); } this.iasapi.setSelection( sel.x1, sel.y1, sel.x2, r ); this.iasapi.update(); } } } } })(jQuery);
01happy-blog
trunk/myblog/wp-admin/js/image-edit.dev.js
JavaScript
oos
14,343
var findPosts; (function($){ findPosts = { open : function(af_name, af_val) { var st = document.documentElement.scrollTop || $(document).scrollTop(); 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':'-250px'}); $('#find-posts-input').focus().keyup(function(e){ if (e.which == 27) { findPosts.close(); } // close on Escape }); return false; }, close : function() { $('#find-posts-response').html(''); $('#find-posts').draggable('destroy').hide(); }, send : function() { var post = { ps: $('#find-posts-input').val(), action: 'find_posts', _ajax_nonce: $('#_ajax_nonce').val(), post_type: $('input[name="find-posts-what"]:checked').val() }; $.ajax({ type : 'POST', url : ajaxurl, data : post, success : function(x) { findPosts.show(x); }, error : function(r) { findPosts.error(r); } }); }, 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); }, 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(); } }); }); }); })(jQuery);
01happy-blog
trunk/myblog/wp-admin/js/media.dev.js
JavaScript
oos
2,193
/** * 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 = $('<div class="nav-tabs-arrow nav-tabs-arrow-left"><a>&laquo;</a></div>'); arrowRight = $('<div class="nav-tabs-arrow nav-tabs-arrow-right"><a>&raquo;</a></div>'); // Attach to the document fixed.wrap('<div class="nav-tabs-nav"/>').parent().prepend( arrowLeft ).append( arrowRight ); // Set the menu tabs api.refreshMenuTabs(); // Make sure the tabs reset on resize $(window).resize(function() { if( resizeTimer ) clearTimeout(resizeTimer); resizeTimer = setTimeout( api.refreshMenuTabs, 200); }); // Build arrow functions $.each([{ arrow : arrowLeft, next : "next", last : "first", operator : "+=" },{ arrow : arrowRight, next : "prev", last : "last", operator : "-=" }], function(){ var that = this; this.arrow.mousedown(function(){ var marginFluidVal = Math.abs( parseInt( fluid.css(marginFluid) ) ), shift = marginFluidVal, css = {}; if( "-=" == that.operator ) shift = Math.abs( tabsWidth - fixed.width() ) - marginFluidVal; if( ! shift ) return; css[marginFluid] = that.operator + shift + 'px'; fluid.animate( css, shift * msPerPx, "linear" ); }).mouseup(function(){ var tab, next; fluid.stop(true); tab = tabs[that.last](); while( (next = tab[that.next]()) && next.length && ! next.isTabVisible() ) { tab = next; } tab.makeTabVisible(); }); }); }, eventOnClickEditLink : function(clickedEl) { var settings, item, matchedSection = /#(.*)$/.exec(clickedEl.href); if ( matchedSection && matchedSection[1] ) { settings = $('#'+matchedSection[1]); item = settings.parent(); if( 0 != item.length ) { if( item.hasClass('menu-item-edit-inactive') ) { if( ! settings.data('menu-item-data') ) { settings.data( 'menu-item-data', settings.getItemData() ); } settings.slideDown('fast'); item.removeClass('menu-item-edit-inactive') .addClass('menu-item-edit-active'); } else { settings.slideUp('fast'); item.removeClass('menu-item-edit-active') .addClass('menu-item-edit-inactive'); } return false; } } }, eventOnClickCancelLink : function(clickedEl) { var settings = $(clickedEl).closest('.menu-item-settings'); settings.setItemData( settings.data('menu-item-data') ); return false; }, eventOnClickMenuSave : function(clickedEl) { var locs = '', menuName = $('#menu-name'), menuNameVal = menuName.val(); // Cancel and warn if invalid menu name if( !menuNameVal || menuNameVal == menuName.attr('title') || !menuNameVal.replace(/\s+/, '') ) { menuName.parent().addClass('form-invalid'); return false; } // Copy menu theme locations $('#nav-menu-theme-locations select').each(function() { locs += '<input type="hidden" name="' + this.name + '" value="' + $(this).val() + '" />'; }); $('#update-nav-menu').append( locs ); // Update menu item position data api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } ); window.onbeforeunload = null; return true; }, eventOnClickMenuDelete : function(clickedEl) { // Delete warning AYS if ( confirm( navMenuL10n.warnDeleteMenu ) ) { window.onbeforeunload = null; return true; } return false; }, eventOnClickMenuItemDelete : function(clickedEl) { var itemID = parseInt(clickedEl.id.replace('delete-', ''), 10); api.removeMenuItem( $('#menu-item-' + itemID) ); api.registerChange(); return false; }, /** * Process the quick search response into a search result * * @param string resp The server response to the query. * @param object req The request arguments. * @param jQuery panel The tabs panel we're searching in. */ processQuickSearchQueryResponse : function(resp, req, panel) { var matched, newID, takenIDs = {}, form = document.getElementById('nav-menu-meta'), pattern = new RegExp('menu-item\\[(\[^\\]\]*)', 'g'), $items = $('<div>').html(resp).find('li'), $item; if( ! $items.length ) { $('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' ); $('img.waiting', panel).hide(); return; } $items.each(function(){ $item = $(this); // make a unique DB ID number matched = pattern.exec($item.html()); if ( matched && matched[1] ) { newID = matched[1]; while( form.elements['menu-item[' + newID + '][menu-item-type]'] || takenIDs[ newID ] ) { newID--; } takenIDs[newID] = true; if ( newID != matched[1] ) { $item.html( $item.html().replace(new RegExp( 'menu-item\\[' + matched[1] + '\\]', 'g'), 'menu-item[' + newID + ']' ) ); } } }); $('.categorychecklist', panel).html( $items ); $('img.waiting', panel).hide(); }, removeMenuItem : function(el) { var children = el.childMenuItems(); el.addClass('deleting').animate({ opacity : 0, height: 0 }, 350, function() { var ins = $('#menu-instructions'); el.remove(); children.shiftDepthClass(-1).updateParentMenuItemDBId(); if( ! ins.siblings().length ) ins.removeClass('menu-instructions-inactive'); }); }, depthToPx : function(depth) { return depth * api.options.menuItemDepthPerLevel; }, pxToDepth : function(px) { return Math.floor(px / api.options.menuItemDepthPerLevel); } }; $(document).ready(function(){ wpNavMenu.init(); }); })(jQuery);
01happy-blog
trunk/myblog/wp-admin/js/nav-menu.dev.js
JavaScript
oos
29,827
/** * PubSub * * A lightweight publish/subscribe implementation. * Private use only! */ var PubSub, fullscreen, wptitlehint; PubSub = function() { this.topics = {}; }; PubSub.prototype.subscribe = function( topic, callback ) { if ( ! this.topics[ topic ] ) this.topics[ topic ] = []; this.topics[ topic ].push( callback ); return callback; }; PubSub.prototype.unsubscribe = function( topic, callback ) { var i, l, topics = this.topics[ topic ]; if ( ! topics ) return callback || []; // Clear matching callbacks if ( callback ) { for ( i = 0, l = topics.length; i < l; i++ ) { if ( callback == topics[i] ) topics.splice( i, 1 ); } return callback; // Clear all callbacks } else { this.topics[ topic ] = []; return topics; } }; PubSub.prototype.publish = function( topic, args ) { var i, l, broken, topics = this.topics[ topic ]; if ( ! topics ) return; args = args || []; for ( i = 0, l = topics.length; i < l; i++ ) { broken = ( topics[i].apply( null, args ) === false || broken ); } return ! broken; }; /** * Distraction Free Writing * (wp-fullscreen) * * Access the API globally using the fullscreen variable. */ (function($){ var api, ps, bounder, s; // Initialize the fullscreen/api object fullscreen = api = {}; // Create the PubSub (publish/subscribe) interface. ps = api.pubsub = new PubSub(); timer = 0; block = false; s = api.settings = { // Settings visible : false, mode : 'tinymce', editor_id : 'content', title_id : '', timer : 0, toolbar_shown : false } /** * Bounder * * Creates a function that publishes start/stop topics. * Used to throttle events. */ bounder = api.bounder = function( start, stop, delay, e ) { var y, top; delay = delay || 1250; if ( e ) { y = e.pageY || e.clientY || e.offsetY; top = $(document).scrollTop(); if ( !e.isDefaultPrevented ) // test if e ic jQuery normalized y = 135 + y; if ( y - top > 120 ) return; } if ( block ) return; block = true; setTimeout( function() { block = false; }, 400 ); if ( s.timer ) clearTimeout( s.timer ); else ps.publish( start ); function timed() { ps.publish( stop ); s.timer = 0; } s.timer = setTimeout( timed, delay ); }; /** * on() * * Turns fullscreen on. * * @param string mode Optional. Switch to the given mode before opening. */ api.on = function() { if ( s.visible ) return; // Settings can be added or changed by defining "wp_fullscreen_settings" JS object. if ( typeof(wp_fullscreen_settings) == 'object' ) $.extend( s, wp_fullscreen_settings ); s.editor_id = wpActiveEditor || 'content'; if ( $('input#title').length && s.editor_id == 'content' ) s.title_id = 'title'; else if ( $('input#' + s.editor_id + '-title').length ) // the title input field should have [editor_id]-title HTML ID to be auto detected s.title_id = s.editor_id + '-title'; else $('#wp-fullscreen-title, #wp-fullscreen-title-prompt-text').hide(); s.mode = $('#' + s.editor_id).is(':hidden') ? 'tinymce' : 'html'; s.qt_canvas = $('#' + s.editor_id).get(0); if ( ! s.element ) api.ui.init(); s.is_mce_on = s.has_tinymce && typeof( tinyMCE.get(s.editor_id) ) != 'undefined'; api.ui.fade( 'show', 'showing', 'shown' ); }; /** * off() * * Turns fullscreen off. */ api.off = function() { if ( ! s.visible ) return; api.ui.fade( 'hide', 'hiding', 'hidden' ); }; /** * switchmode() * * @return string - The current mode. * * @param string to - The fullscreen mode to switch to. * @event switchMode * @eventparam string to - The new mode. * @eventparam string from - The old mode. */ api.switchmode = function( to ) { var from = s.mode; if ( ! to || ! s.visible || ! s.has_tinymce ) return from; // Don't switch if the mode is the same. if ( from == to ) return from; ps.publish( 'switchMode', [ from, to ] ); s.mode = to; ps.publish( 'switchedMode', [ from, to ] ); return to; }; /** * General */ api.save = function() { var hidden = $('#hiddenaction'), old = hidden.val(), spinner = $('#wp-fullscreen-save img'), message = $('#wp-fullscreen-save span'); spinner.show(); api.savecontent(); hidden.val('wp-fullscreen-save-post'); $.post( ajaxurl, $('form#post').serialize(), function(r){ spinner.hide(); message.show(); setTimeout( function(){ message.fadeOut(1000); }, 3000 ); if ( r.last_edited ) $('#wp-fullscreen-save input').attr( 'title', r.last_edited ); }, 'json'); hidden.val(old); } api.savecontent = function() { var ed, content; if ( s.title_id ) $('#' + s.title_id).val( $('#wp-fullscreen-title').val() ); if ( s.mode === 'tinymce' && (ed = tinyMCE.get('wp_mce_fullscreen')) ) { content = ed.save(); } else { content = $('#wp_mce_fullscreen').val(); } $('#' + s.editor_id).val( content ); $(document).triggerHandler('wpcountwords', [ content ]); } set_title_hint = function( title ) { if ( ! title.val().length ) title.siblings('label').css( 'visibility', '' ); else title.siblings('label').css( 'visibility', 'hidden' ); } api.dfw_width = function(n) { var el = $('#wp-fullscreen-wrap'), w = el.width(); if ( !n ) { // reset to theme width el.width( $('#wp-fullscreen-central-toolbar').width() ); deleteUserSetting('dfw_width'); return; } w = n + w; if ( w < 200 || w > 1200 ) // sanity check return; el.width( w ); setUserSetting('dfw_width', w); } ps.subscribe( 'showToolbar', function() { s.toolbars.removeClass('fade-1000').addClass('fade-300'); api.fade.In( s.toolbars, 300, function(){ ps.publish('toolbarShown'); }, true ); $('#wp-fullscreen-body').addClass('wp-fullscreen-focus'); s.toolbar_shown = true; }); ps.subscribe( 'hideToolbar', function() { s.toolbars.removeClass('fade-300').addClass('fade-1000'); api.fade.Out( s.toolbars, 1000, function(){ ps.publish('toolbarHidden'); }, true ); $('#wp-fullscreen-body').removeClass('wp-fullscreen-focus'); }); ps.subscribe( 'toolbarShown', function() { s.toolbars.removeClass('fade-300'); }); ps.subscribe( 'toolbarHidden', function() { s.toolbars.removeClass('fade-1000'); s.toolbar_shown = false; }); ps.subscribe( 'show', function() { // This event occurs before the overlay blocks the UI. var title; if ( s.title_id ) { title = $('#wp-fullscreen-title').val( $('#' + s.title_id).val() ); set_title_hint( title ); } $('#wp-fullscreen-save input').attr( 'title', $('#last-edit').text() ); s.textarea_obj.value = s.qt_canvas.value; if ( s.has_tinymce && s.mode === 'tinymce' ) tinyMCE.execCommand('wpFullScreenInit'); s.orig_y = $(window).scrollTop(); }); ps.subscribe( 'showing', function() { // This event occurs while the DFW overlay blocks the UI. $( document.body ).addClass( 'fullscreen-active' ); api.refresh_buttons(); $( document ).bind( 'mousemove.fullscreen', function(e) { bounder( 'showToolbar', 'hideToolbar', 2000, e ); } ); bounder( 'showToolbar', 'hideToolbar', 2000 ); api.bind_resize(); setTimeout( api.resize_textarea, 200 ); // scroll to top so the user is not disoriented scrollTo(0, 0); // needed it for IE7 and compat mode $('#wpadminbar').hide(); }); ps.subscribe( 'shown', function() { // This event occurs after the DFW overlay is shown var interim_init; s.visible = true; // init the standard TinyMCE instance if missing if ( s.has_tinymce && ! s.is_mce_on ) { interim_init = function(mce, ed) { var el = ed.getElement(), old_val = el.value, settings = tinyMCEPreInit.mceInit[s.editor_id]; if ( settings && settings.wpautop && typeof(switchEditors) != 'undefined' ) el.value = switchEditors.wpautop( el.value ); ed.onInit.add(function(ed) { ed.hide(); ed.getElement().value = old_val; tinymce.onAddEditor.remove(interim_init); }); }; tinymce.onAddEditor.add(interim_init); tinyMCE.init(tinyMCEPreInit.mceInit[s.editor_id]); s.is_mce_on = true; } wpActiveEditor = 'wp_mce_fullscreen'; }); ps.subscribe( 'hide', function() { // This event occurs before the overlay blocks DFW. var htmled_is_hidden = $('#' + s.editor_id).is(':hidden'); // Make sure the correct editor is displaying. if ( s.has_tinymce && s.mode === 'tinymce' && !htmled_is_hidden ) { switchEditors.go(s.editor_id, 'tmce'); } else if ( s.mode === 'html' && htmled_is_hidden ) { switchEditors.go(s.editor_id, 'html'); } // Save content must be after switchEditors or content will be overwritten. See #17229. api.savecontent(); $( document ).unbind( '.fullscreen' ); $(s.textarea_obj).unbind('.grow'); if ( s.has_tinymce && s.mode === 'tinymce' ) tinyMCE.execCommand('wpFullScreenSave'); if ( s.title_id ) set_title_hint( $('#' + s.title_id) ); s.qt_canvas.value = s.textarea_obj.value; }); ps.subscribe( 'hiding', function() { // This event occurs while the overlay blocks the DFW UI. $( document.body ).removeClass( 'fullscreen-active' ); scrollTo(0, s.orig_y); $('#wpadminbar').show(); }); ps.subscribe( 'hidden', function() { // This event occurs after DFW is removed. s.visible = false; $('#wp_mce_fullscreen, #wp-fullscreen-title').removeAttr('style'); if ( s.has_tinymce && s.is_mce_on ) tinyMCE.execCommand('wpFullScreenClose'); s.textarea_obj.value = ''; api.oldheight = 0; wpActiveEditor = s.editor_id; }); ps.subscribe( 'switchMode', function( from, to ) { var ed; if ( !s.has_tinymce || !s.is_mce_on ) return; ed = tinyMCE.get('wp_mce_fullscreen'); if ( from === 'html' && to === 'tinymce' ) { if ( tinyMCE.get(s.editor_id).getParam('wpautop') && typeof(switchEditors) != 'undefined' ) s.textarea_obj.value = switchEditors.wpautop( s.textarea_obj.value ); if ( 'undefined' == typeof(ed) ) tinyMCE.execCommand('wpFullScreenInit'); else ed.show(); } else if ( from === 'tinymce' && to === 'html' ) { if ( ed ) ed.hide(); } }); ps.subscribe( 'switchedMode', function( from, to ) { api.refresh_buttons(true); if ( to === 'html' ) setTimeout( api.resize_textarea, 200 ); }); /** * Buttons */ api.b = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('Bold'); } api.i = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('Italic'); } api.ul = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('InsertUnorderedList'); } api.ol = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('InsertOrderedList'); } api.link = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('WP_Link'); else wpLink.open(); } api.unlink = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('unlink'); } api.atd = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('mceWritingImprovementTool'); } api.help = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('WP_Help'); } api.blockquote = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) tinyMCE.execCommand('mceBlockQuote'); } api.medialib = function() { if ( s.has_tinymce && 'tinymce' === s.mode ) { tinyMCE.execCommand('WP_Medialib'); } else { var href = $('#wp-' + s.editor_id + '-media-buttons a.thickbox').attr('href') || ''; if ( href ) tb_show('', href); } } api.refresh_buttons = function( fade ) { fade = fade || false; if ( s.mode === 'html' ) { $('#wp-fullscreen-mode-bar').removeClass('wp-tmce-mode').addClass('wp-html-mode'); if ( fade ) $('#wp-fullscreen-button-bar').fadeOut( 150, function(){ $(this).addClass('wp-html-mode').fadeIn( 150 ); }); else $('#wp-fullscreen-button-bar').addClass('wp-html-mode'); } else if ( s.mode === 'tinymce' ) { $('#wp-fullscreen-mode-bar').removeClass('wp-html-mode').addClass('wp-tmce-mode'); if ( fade ) $('#wp-fullscreen-button-bar').fadeOut( 150, function(){ $(this).removeClass('wp-html-mode').fadeIn( 150 ); }); else $('#wp-fullscreen-button-bar').removeClass('wp-html-mode'); } } /** * UI Elements * * Used for transitioning between states. */ api.ui = { init: function() { var topbar = $('#fullscreen-topbar'), txtarea = $('#wp_mce_fullscreen'), last = 0; s.toolbars = topbar.add( $('#wp-fullscreen-status') ); s.element = $('#fullscreen-fader'); s.textarea_obj = txtarea[0]; s.has_tinymce = typeof(tinymce) != 'undefined'; if ( !s.has_tinymce ) $('#wp-fullscreen-mode-bar').hide(); if ( wptitlehint && $('#wp-fullscreen-title').length ) wptitlehint('wp-fullscreen-title'); $(document).keyup(function(e){ var c = e.keyCode || e.charCode, a, data; if ( !fullscreen.settings.visible ) return true; if ( navigator.platform && navigator.platform.indexOf('Mac') != -1 ) a = e.ctrlKey; // Ctrl key for Mac else a = e.altKey; // Alt key for Win & Linux if ( 27 == c ) { // Esc data = { event: e, what: 'dfw', cb: fullscreen.off, condition: function(){ if ( $('#TB_window').is(':visible') || $('.wp-dialog').is(':visible') ) return false; return true; } }; if ( ! jQuery(document).triggerHandler( 'wp_CloseOnEscape', [data] ) ) fullscreen.off(); } if ( a && (61 == c || 107 == c || 187 == c) ) // + api.dfw_width(25); if ( a && (45 == c || 109 == c || 189 == c) ) // - api.dfw_width(-25); if ( a && 48 == c ) // 0 api.dfw_width(0); return false; }); // word count in HTML mode if ( typeof(wpWordCount) != 'undefined' ) { txtarea.keyup( function(e) { var k = e.keyCode || e.charCode; if ( k == last ) return true; if ( 13 == k || 8 == last || 46 == last ) $(document).triggerHandler('wpcountwords', [ txtarea.val() ]); last = k; return true; }); } topbar.mouseenter(function(e){ s.toolbars.addClass('fullscreen-make-sticky'); $( document ).unbind( '.fullscreen' ); clearTimeout( s.timer ); s.timer = 0; }).mouseleave(function(e){ s.toolbars.removeClass('fullscreen-make-sticky'); if ( s.visible ) $( document ).bind( 'mousemove.fullscreen', function(e) { bounder( 'showToolbar', 'hideToolbar', 2000, e ); } ); }); }, fade: function( before, during, after ) { if ( ! s.element ) api.ui.init(); // If any callback bound to before returns false, bail. if ( before && ! ps.publish( before ) ) return; api.fade.In( s.element, 600, function() { if ( during ) ps.publish( during ); api.fade.Out( s.element, 600, function() { if ( after ) ps.publish( after ); }) }); } }; api.fade = { transitionend: 'transitionend webkitTransitionEnd oTransitionEnd', // Sensitivity to allow browsers to render the blank element before animating. sensitivity: 100, In: function( element, speed, callback, stop ) { callback = callback || $.noop; speed = speed || 400; stop = stop || false; if ( api.fade.transitions ) { if ( element.is(':visible') ) { element.addClass( 'fade-trigger' ); return element; } element.show(); element.first().one( this.transitionend, function() { callback(); }); setTimeout( function() { element.addClass( 'fade-trigger' ); }, this.sensitivity ); } else { if ( stop ) element.stop(); element.css( 'opacity', 1 ); element.first().fadeIn( speed, callback ); if ( element.length > 1 ) element.not(':first').fadeIn( speed ); } return element; }, Out: function( element, speed, callback, stop ) { callback = callback || $.noop; speed = speed || 400; stop = stop || false; if ( ! element.is(':visible') ) return element; if ( api.fade.transitions ) { element.first().one( api.fade.transitionend, function() { if ( element.hasClass('fade-trigger') ) return; element.hide(); callback(); }); setTimeout( function() { element.removeClass( 'fade-trigger' ); }, this.sensitivity ); } else { if ( stop ) element.stop(); element.first().fadeOut( speed, callback ); if ( element.length > 1 ) element.not(':first').fadeOut( speed ); } return element; }, transitions: (function() { // Check if the browser supports CSS 3.0 transitions var s = document.documentElement.style; return ( typeof ( s.WebkitTransition ) == 'string' || typeof ( s.MozTransition ) == 'string' || typeof ( s.OTransition ) == 'string' || typeof ( s.transition ) == 'string' ); })() }; /** * Resize API * * Automatically updates textarea height. */ api.bind_resize = function() { $(s.textarea_obj).bind('keypress.grow click.grow paste.grow', function(){ setTimeout( api.resize_textarea, 200 ); }); } api.oldheight = 0; api.resize_textarea = function() { var txt = s.textarea_obj, newheight; newheight = txt.scrollHeight > 300 ? txt.scrollHeight : 300; if ( newheight != api.oldheight ) { txt.style.height = newheight + 'px'; api.oldheight = newheight; } }; })(jQuery);
01happy-blog
trunk/myblog/wp-admin/js/wp-fullscreen.dev.js
JavaScript
oos
17,396
var theList, theExtraList, toggleWithKeyboard = false; (function($) { var getCount, updateCount, updatePending, dashboardTotals; setCommentsList = function() { var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList; totalInput = $('input[name="_total"]', '#comments-form'); perPageInput = $('input[name="_per_page"]', '#comments-form'); pageInput = $('input[name="_page"]', '#comments-form'); dimAfter = function( r, settings ) { var c = $('#' + settings.element), editRow, replyID, replyButton; editRow = $('#replyrow'); replyID = $('#comment_ID', editRow).val(); replyButton = $('#replybtn', editRow); if ( c.is('.unapproved') ) { if ( settings.data.id == replyID ) replyButton.text(adminCommentsL10n.replyApprove); c.find('div.comment_status').html('0'); } else { if ( settings.data.id == replyID ) replyButton.text(adminCommentsL10n.reply); c.find('div.comment_status').html('1'); } var diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; updatePending( diff ); }; // Send current total, page, per_page and url delBefore = function( settings, list ) { var cl = $(settings.target).attr('class'), id, el, n, h, a, author, action = false; settings.data._total = totalInput.val() || 0; settings.data._per_page = perPageInput.val() || 0; settings.data._page = pageInput.val() || 0; settings.data._url = document.location.href; settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val(); if ( cl.indexOf(':trash=1') != -1 ) action = 'trash'; else if ( cl.indexOf(':spam=1') != -1 ) action = 'spam'; if ( action ) { id = cl.replace(/.*?comment-([0-9]+).*/, '$1'); el = $('#comment-' + id); note = $('#' + action + '-undo-holder').html(); el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits. if ( el.siblings('#replyrow').length && commentReply.cid == id ) commentReply.close(); if ( el.is('tr') ) { n = el.children(':visible').length; author = $('.author strong', el).text(); h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>'); } else { author = $('.comment-author', el).text(); h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>'); } el.before(h); $('strong', '#undo-' + id).text(author); a = $('.undo a', '#undo-' + id); a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce); a.attr('class', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive'); $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); a.click(function(){ list.wpList.del(this); $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){ $(this).remove(); $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() }); }); return false; }); } return settings; }; // Updates the current total (stored in the _total input) updateTotalCount = function( total, time, setConfidentTime ) { if ( time < lastConfidentTime ) return; if ( setConfidentTime ) lastConfidentTime = time; totalInput.val( total.toString() ); }; dashboardTotals = function(n) { var dash = $('#dashboard_right_now'), total, appr, totalN, apprN; n = n || 0; if ( isNaN(n) || !dash.length ) return; total = $('span.total-count', dash); appr = $('span.approved-count', dash); totalN = getCount(total); totalN = totalN + n; apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) ); updateCount(total, totalN); updateCount(appr, apprN); }; getCount = function(el) { var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); if ( isNaN(n) ) return 0; return n; }; updateCount = function(el, n) { var n1 = ''; if ( isNaN(n) ) return; n = n < 1 ? '0' : n.toString(); if ( n.length > 3 ) { while ( n.length > 3 ) { n1 = thousandsSeparator + n.substr(n.length - 3) + n1; n = n.substr(0, n.length - 3); } n = n + n1; } el.html(n); }; updatePending = function( diff ) { $('span.pending-count').each(function() { var a = $(this), n = getCount(a) + diff; if ( n < 1 ) n = 0; a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); updateCount( a, n ); }); dashboardTotals(); }; // In admin-ajax.php, we send back the unix time stamp instead of 1 on success delAfter = function( r, settings ) { var total, N, spam, trash, pending, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), unapproved = $('#' + settings.element).is('.unapproved'); function getUpdate(s) { if ( $(settings.target).parent().is('span.' + s) ) return 1; else if ( $('#' + settings.element).is('.' + s) ) return -1; return 0; } if ( untrash ) trash = -1; else trash = getUpdate('trash'); if ( unspam ) spam = -1; else spam = getUpdate('spam'); if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending, // or a trash/spam of a pending comment was undone pending = 1; } else if ( unapproved ) { // a pending comment was trashed/spammed/approved pending = -1; } if ( pending ) updatePending(pending); $('span.spam-count').each( function() { var a = $(this), n = getCount(a) + spam; updateCount(a, n); }); $('span.trash-count').each( function() { var a = $(this), n = getCount(a) + trash; updateCount(a, n); }); if ( $('#dashboard_right_now').length ) { N = trash ? -1 * trash : 0; dashboardTotals(N); } else { total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; if ( $(settings.target).parent().is('span.undo') ) total++; else total--; if ( total < 0 ) total = 0; if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || ''; if ( total_items_i18n ) { $('.displaying-num').text( total_items_i18n ); $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n ); $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val()); } updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true ); } else { updateTotalCount( total, r, false ); } } if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) { return; } theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() ); refillTheExtraList(); }; refillTheExtraList = function(ev) { var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val(); if (! args.paged) args.paged = 1; if (args.paged > total_pages) { return; } if (ev) { theExtraList.empty(); args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php } else { args.number = 1; args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list } args.no_placeholder = true; args.paged ++; // $.query.get() needs some correction to be sent into an ajax request if ( true === args.comment_type ) args.comment_type = ''; args = $.extend(args, { 'action': 'fetch-list', 'list_args': list_args, '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val() }); $.ajax({ url: ajaxurl, global: false, dataType: 'json', data: args, success: function(response) { theExtraList.get(0).wpList.add( response.rows ); } }); }; theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) .bind('wpListDelEnd', function(e, s){ var id = s.element.replace(/[^0-9]+/g, ''); if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 ) $('#undo-' + id).fadeIn(300, function(){ $(this).show() }); }); }; commentReply = { cid : '', act : '', init : function() { var row = $('#replyrow'); $('a.cancel', row).click(function() { return commentReply.revert(); }); $('a.save', row).click(function() { return commentReply.send(); }); $('input#author, input#author-email, input#author-url', row).keypress(function(e){ if ( e.which == 13 ) { commentReply.send(); e.preventDefault(); return false; } }); // add events $('#the-comment-list .column-comment > p').dblclick(function(){ commentReply.toggle($(this).parent()); }); $('#doaction, #doaction2, #post-query-submit').click(function(e){ if ( $('#the-comment-list #replyrow').length > 0 ) commentReply.close(); }); this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || ''; /* $(listTable).bind('beforeChangePage', function(){ commentReply.close(); }); */ }, addEvents : function(r) { r.each(function() { $(this).find('.column-comment > p').dblclick(function(){ commentReply.toggle($(this).parent()); }); }); }, toggle : function(el) { if ( $(el).css('display') != 'none' ) $(el).find('a.vim-q').click(); }, revert : function() { if ( $('#the-comment-list #replyrow').length < 1 ) return false; $('#replyrow').fadeOut('fast', function(){ commentReply.close(); }); return false; }, close : function() { var c, replyrow = $('#replyrow'); // replyrow is not showing? if ( replyrow.parent().is('#com-reply') ) return; if ( this.cid && this.act == 'edit-comment' ) { c = $('#comment-' + this.cid); c.fadeIn(300, function(){ c.show() }).css('backgroundColor', ''); } // reset the Quicktags buttons if ( typeof QTags != 'undefined' ) QTags.closeAllTags('replycontent'); $('#add-new-comment').css('display', ''); replyrow.hide(); $('#com-reply').append( replyrow ); $('#replycontent').css('height', '').val(''); $('#edithead input').val(''); $('.error', replyrow).html('').hide(); $('.waiting', replyrow).hide(); this.cid = ''; }, open : function(comment_id, post_id, action) { var t = this, editRow, rowData, act, c = $('#comment-' + comment_id), h = c.height(), replyButton; t.close(); t.cid = comment_id; editRow = $('#replyrow'); rowData = $('#inline-'+comment_id); action = action || 'replyto'; act = 'edit' == action ? 'edit' : 'replyto'; act = t.act = act + '-comment'; $('#action', editRow).val(act); $('#comment_post_ID', editRow).val(post_id); $('#comment_ID', editRow).val(comment_id); if ( h > 120 ) $('#replycontent', editRow).css('height', (35+h) + 'px'); if ( action == 'edit' ) { $('#author', editRow).val( $('div.author', rowData).text() ); $('#author-email', editRow).val( $('div.author-email', rowData).text() ); $('#author-url', editRow).val( $('div.author-url', rowData).text() ); $('#status', editRow).val( $('div.comment_status', rowData).text() ); $('#replycontent', editRow).val( $('textarea.comment', rowData).val() ); $('#edithead, #savebtn', editRow).show(); $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide(); c.after( editRow ).fadeOut('fast', function(){ $('#replyrow').fadeIn(300, function(){ $(this).show() }); }); } else if ( action == 'add' ) { $('#addhead, #addbtn', editRow).show(); $('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide(); $('#the-comment-list').prepend(editRow); $('#replyrow').fadeIn(300); } else { replyButton = $('#replybtn', editRow); $('#edithead, #savebtn, #addhead, #addbtn', editRow).hide(); $('#replyhead, #replybtn', editRow).show(); c.after(editRow); if ( c.hasClass('unapproved') ) { replyButton.text(adminCommentsL10n.replyApprove); } else { replyButton.text(adminCommentsL10n.reply); } $('#replyrow').fadeIn(300, function(){ $(this).show() }); } setTimeout(function() { var rtop, rbottom, scrollTop, vp, scrollBottom; rtop = $('#replyrow').offset().top; rbottom = rtop + $('#replyrow').height(); scrollTop = window.pageYOffset || document.documentElement.scrollTop; vp = document.documentElement.clientHeight || self.innerHeight || 0; scrollBottom = scrollTop + vp; if ( scrollBottom - 20 < rbottom ) window.scroll(0, rbottom - vp + 35); else if ( rtop - 20 < scrollTop ) window.scroll(0, rtop - 35); $('#replycontent').focus().keyup(function(e){ if ( e.which == 27 ) commentReply.revert(); // close on Escape }); }, 600); return false; }, send : function() { var post = {}; $('#replysubmit .error').hide(); $('#replysubmit .waiting').show(); $('#replyrow input').not(':button').each(function() { var t = $(this); post[ t.attr('name') ] = t.val(); }); post.content = $('#replycontent').val(); post.id = post.comment_post_ID; post.comments_listing = this.comments_listing; post.p = $('[name="p"]').val(); if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') ) post.approve_parent = 1; $.ajax({ type : 'POST', url : ajaxurl, data : post, success : function(x) { commentReply.show(x); }, error : function(r) { commentReply.error(r); } }); return false; }, show : function(xml) { var t = this, r, c, id, bg, pid; if ( typeof(xml) == 'string' ) { t.error({'responseText': xml}); return false; } r = wpAjax.parseAjaxResponse(xml); if ( r.errors ) { t.error({'responseText': wpAjax.broken}); return false; } t.revert(); r = r.responses[0]; c = r.data; id = '#comment-' + r.id; if ( 'edit-comment' == t.act ) $(id).remove(); if ( r.supplemental.parent_approved ) { pid = $('#comment-' + r.supplemental.parent_approved); updatePending( -1 ); if ( this.comments_listing == 'moderated' ) { pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){ pid.fadeOut(); }); return; } } $(c).hide() $('#replyrow').after(c); id = $(id); t.addEvents(id); bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor'); id.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) .animate( { 'backgroundColor': bg }, 300, function() { if ( pid && pid.length ) { pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) .animate( { 'backgroundColor': bg }, 300 ) .removeClass('unapproved').addClass('approved') .find('div.comment_status').html('1'); } }); }, error : function(r) { var er = r.statusText; $('#replysubmit .waiting').hide(); if ( r.responseText ) er = r.responseText.replace( /<.[^<>]*?>/g, '' ); if ( er ) $('#replysubmit .error').html(er).show(); }, addcomment: function(post_id) { var t = this; $('#add-new-comment').fadeOut(200, function(){ t.open(0, post_id, 'add'); $('table.comments-box').css('display', ''); $('#no-comments').remove(); }); } }; $(document).ready(function(){ var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk; setCommentsList(); commentReply.init(); $(document).delegate('span.delete a.delete', 'click', function(){return false;}); if ( typeof $.table_hotkeys != 'undefined' ) { make_hotkeys_redirect = function(which) { return function() { var first_last, l; first_last = 'next' == which? 'first' : 'last'; l = $('.tablenav-pages .'+which+'-page:not(.disabled)'); if (l.length) window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; } }; edit_comment = function(event, current_row) { window.location = $('span.edit a', current_row).attr('href'); }; toggle_all = function() { toggleWithKeyboard = true; $('input:checkbox', '#cb').click().prop('checked', false); toggleWithKeyboard = false; }; make_bulk = function(value) { return function() { var scope = $('select[name="action"]'); $('option[value="' + value + '"]', scope).prop('selected', true); $('#doaction').click(); } }; $.table_hotkeys( $('table.widefat'), ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all], ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')], ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')], ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]], { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last, prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') } ); } }); })(jQuery);
01happy-blog
trunk/myblog/wp-admin/js/edit-comments.dev.js
JavaScript
oos
17,393
var thickDims, tbWidth, tbHeight; jQuery(document).ready(function($) { thickDims = function() { var tbWindow = $('#TB_window'), H = $(window).height(), W = $(window).width(), w, h; w = (tbWidth && tbWidth < W - 90) ? tbWidth : W - 90; h = (tbHeight && tbHeight < H - 60) ? tbHeight : H - 60; if ( tbWindow.size() ) { tbWindow.width(w).height(h); $('#TB_iframeContent').width(w).height(h - 27); tbWindow.css({'margin-left': '-' + parseInt((w / 2),10) + 'px'}); if ( typeof document.body.style.maxWidth != 'undefined' ) tbWindow.css({'top':'30px','margin-top':'0'}); } }; thickDims(); $(window).resize( function() { thickDims() } ); $('a.thickbox-preview').click( function() { tb_click.call(this); var alink = $(this).parents('.available-theme').find('.activatelink'), link = '', href = $(this).attr('href'), url, text; if ( tbWidth = href.match(/&tbWidth=[0-9]+/) ) tbWidth = parseInt(tbWidth[0].replace(/[^0-9]+/g, ''), 10); else tbWidth = $(window).width() - 90; if ( tbHeight = href.match(/&tbHeight=[0-9]+/) ) tbHeight = parseInt(tbHeight[0].replace(/[^0-9]+/g, ''), 10); else tbHeight = $(window).height() - 60; if ( alink.length ) { url = alink.attr('href') || ''; text = alink.attr('title') || ''; link = '&nbsp; <a href="' + url + '" target="_top" class="tb-theme-preview-link">' + text + '</a>'; } else { text = $(this).attr('title') || ''; link = '&nbsp; <span class="tb-theme-preview-link">' + text + '</span>'; } $('#TB_title').css({'background-color':'#222','color':'#dfdfdf'}); $('#TB_closeAjaxWindow').css({'float':'left'}); $('#TB_ajaxWindowTitle').css({'float':'right'}).html(link); $('#TB_iframeContent').width('100%'); thickDims(); return false; } ); });
01happy-blog
trunk/myblog/wp-admin/js/theme-preview.dev.js
JavaScript
oos
1,775
var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad; jQuery(document).ready( function($) { /* Dashboard Welcome Panel */ var welcomePanel = $('#welcome-panel'), welcomePanelHide = $('#wp_welcome_panel-hide'), updateWelcomePanel = function( visible ) { $.post( ajaxurl, { action: 'update-welcome-panel', visible: visible, welcomepanelnonce: $('#welcomepanelnonce').val() }); }; if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) welcomePanel.removeClass('hidden'); $('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) { e.preventDefault(); welcomePanel.addClass('hidden'); updateWelcomePanel( 0 ); $('#wp_welcome_panel-hide').prop('checked', false); }); welcomePanelHide.click( function() { welcomePanel.toggleClass('hidden', ! this.checked ); updateWelcomePanel( this.checked ? 1 : 0 ); }); // These widgets are sometimes populated via ajax ajaxWidgets = [ 'dashboard_incoming_links', 'dashboard_primary', 'dashboard_secondary', 'dashboard_plugins' ]; ajaxPopulateWidgets = function(el) { function show(i, id) { var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading'); if ( e.length ) { p = e.parent(); setTimeout( function(){ p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id, '', function() { p.hide().slideDown('normal', function(){ $(this).css('display', ''); }); }); }, i * 500 ); } } if ( el ) { el = el.toString(); if ( $.inArray(el, ajaxWidgets) != -1 ) show(0, el); } else { $.each( ajaxWidgets, show ); } }; ajaxPopulateWidgets(); postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } ); /* QuickPress */ quickPressLoad = function() { var act = $('#quickpost-action'), t; t = $('#quick-press').submit( function() { $('#dashboard_quick_press #publishing-action img.waiting').css('visibility', 'visible'); $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true); if ( 'post' == act.val() ) { act.val( 'post-quickpress-publish' ); } $('#dashboard_quick_press div.inside').load( t.attr( 'action' ), t.serializeArray(), function() { $('#dashboard_quick_press #publishing-action img.waiting').css('visibility', 'hidden'); $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', false); $('#dashboard_quick_press ul').next('p').remove(); $('#dashboard_quick_press ul').find('li').each( function() { $('#dashboard_recent_drafts ul').prepend( this ); } ).end().remove(); quickPressLoad(); } ); return false; } ); $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } ); }; quickPressLoad(); } );
01happy-blog
trunk/myblog/wp-admin/js/dashboard.dev.js
JavaScript
oos
2,835
jQuery(document).ready( function($) { var before, addBefore, addAfter, delBefore; before = function() { var nonce = $('#newmeta [name="_ajax_nonce"]').val(), postId = $('#post_ID').val(); if ( !nonce || !postId ) { return false; } return [nonce,postId]; } addBefore = function( s ) { var b = before(); if ( !b ) { return false; } s.data = s.data.replace(/_ajax_nonce=[a-f0-9]+/, '_ajax_nonce=' + b[0]) + '&post_id=' + b[1]; return s; }; addAfter = function( r, s ) { var postId = $('postid', r).text(), h; if ( !postId ) { return; } $('#post_ID').attr( 'name', 'post_ID' ).val( postId ); h = $('#hiddenaction'); if ( 'post' == h.val() ) { h.val( 'postajaxpost' ); } }; delBefore = function( s ) { var b = before(); if ( !b ) return false; s.data._ajax_nonce = b[0]; s.data.post_id = b[1]; return s; } $('#the-list') .wpList( { addBefore: addBefore, addAfter: addAfter, delBefore: delBefore } ) .find('.updatemeta, .deletemeta').attr( 'type', 'button' ); } );
01happy-blog
trunk/myblog/wp-admin/js/custom-fields.dev.js
JavaScript
oos
1,008
var postboxes; (function($) { postboxes = { add_postbox_toggles : function(page, args) { var self = this; self.init(page, args); $('.postbox h3, .postbox .handlediv').bind('click.postboxes', function() { var p = $(this).parent('.postbox'), id = p.attr('id'); if ( 'dashboard_browser_nag' == id ) return; p.toggleClass('closed'); if ( page != 'press-this' ) self.save_state(page); if ( id ) { if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) ) self.pbshow(id); else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) ) self.pbhide(id); } }); $('.postbox h3 a').click( function(e) { e.stopPropagation(); }); $('.postbox a.dismiss').bind('click.postboxes', function(e) { var hide_id = $(this).parents('.postbox').attr('id') + '-hide'; $( '#' + hide_id ).prop('checked', false).triggerHandler('click'); return false; }); $('.hide-postbox-tog').bind('click.postboxes', function() { var box = $(this).val(); if ( $(this).prop('checked') ) { $('#' + box).show(); if ( $.isFunction( postboxes.pbshow ) ) self.pbshow( box ); } else { $('#' + box).hide(); if ( $.isFunction( postboxes.pbhide ) ) self.pbhide( box ); } self.save_state(page); self._mark_area(); }); $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){ var n = parseInt($(this).val(), 10); if ( n ) { self._pb_edit(n); self.save_order(page); } }); }, init : function(page, args) { var isMobile = $(document.body).hasClass('mobile'); $.extend( this, args || {} ); $('#wpbody-content').css('overflow','hidden'); $('.meta-box-sortables').sortable({ placeholder: 'sortable-placeholder', connectWith: '.meta-box-sortables', items: '.postbox', handle: '.hndle', cursor: 'move', delay: ( isMobile ? 200 : 0 ), distance: 2, tolerance: 'pointer', forcePlaceholderSize: true, helper: 'clone', opacity: 0.65, stop: function(e,ui) { if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) { $(this).sortable('cancel'); return; } postboxes.save_order(page); }, receive: function(e,ui) { if ( 'dashboard_browser_nag' == ui.item[0].id ) $(ui.sender).sortable('cancel'); postboxes._mark_area(); } }); if ( isMobile ) { $(document.body).bind('orientationchange.postboxes', function(){ postboxes._pb_change(); }); this._pb_change(); } this._mark_area(); }, save_state : function(page) { var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','), hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(','); $.post(ajaxurl, { action: 'closed-postboxes', closed: closed, hidden: hidden, closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), page: page }); }, save_order : function(page) { var postVars, page_columns = $('.columns-prefs input:checked').val() || 0; postVars = { action: 'meta-box-order', _ajax_nonce: $('#meta-box-order-nonce').val(), page_columns: page_columns, page: page } $('.meta-box-sortables').each( function() { postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(','); } ); $.post( ajaxurl, postVars ); }, _mark_area : function() { var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables'); $('#dashboard-widgets .meta-box-sortables:visible').each(function(n, el){ var t = $(this); if ( visible == 1 || t.children('.postbox:visible').length ) t.removeClass('empty-container'); else t.addClass('empty-container'); }); if ( side.length ) { if ( side.children('.postbox:visible').length ) side.removeClass('empty-container'); else if ( $('#postbox-container-1').css('width') == '280px' ) side.addClass('empty-container'); } }, _pb_edit : function(n) { var el = $('.metabox-holder').get(0); el.className = el.className.replace(/columns-\d+/, 'columns-' + n); }, _pb_change : function() { switch ( window.orientation ) { case 90: case -90: this._pb_edit(2); break; case 0: case 180: if ( $('#poststuff').length ) this._pb_edit(1); else this._pb_edit(2); break; } }, /* Callbacks */ pbshow : false, pbhide : false }; }(jQuery));
01happy-blog
trunk/myblog/wp-admin/js/postbox.dev.js
JavaScript
oos
4,600
function WPSetAsThumbnail(id, nonce){ var $link = jQuery('a#wp-post-thumbnail-' + id); $link.text( setPostThumbnailL10n.saving ); jQuery.post(ajaxurl, { action:"set-post-thumbnail", post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie) }, function(str){ var win = window.dialogArguments || opener || parent || top; $link.text( setPostThumbnailL10n.setThumbnail ); if ( str == '0' ) { alert( setPostThumbnailL10n.error ); } else { jQuery('a.wp-post-thumbnail').show(); $link.text( setPostThumbnailL10n.done ); $link.fadeOut( 2000 ); win.WPSetThumbnailID(id); win.WPSetThumbnailHTML(str); } } ); }
01happy-blog
trunk/myblog/wp-admin/js/set-post-thumbnail.dev.js
JavaScript
oos
679
<?php /** * About This Version administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once( './admin.php' ); $title = __( 'About' ); list( $display_version ) = explode( '-', $wp_version ); include( ABSPATH . 'wp-admin/admin-header.php' ); ?> <div class="wrap about-wrap"> <h1><?php printf( __( 'Welcome to WordPress %s' ), $display_version ); ?></h1> <div class="about-text"><?php printf( __( 'Thank you for updating to the latest version! WordPress %s is already making your website better, faster, and more attractive, just like you!' ), $display_version ); ?></div> <div class="wp-badge"><?php printf( __( 'Version %s' ), $display_version ); ?></div> <h2 class="nav-tab-wrapper"> <a href="about.php" class="nav-tab nav-tab-active"> <?php _e( 'What&#8217;s New' ); ?> </a><a href="credits.php" class="nav-tab"> <?php _e( 'Credits' ); ?> </a><a href="freedoms.php" class="nav-tab"> <?php _e( 'Freedoms' ); ?> </a> </h2> <div class="changelog point-releases"> <h3><?php echo _n( 'Maintenance and Security Release', 'Maintenance and Security Releases', 1 ); ?></h3> <p><?php printf( _n( '<strong>Version %1$s</strong> addressed some security issues and fixed %2$s bug.', '<strong>Version %1$s</strong> addressed some security issues and fixed %2$s bugs.', 21 ), '3.4.1', number_format_i18n( 21 ) ); ?> <?php printf( __( 'For more information, see <a href="%s">the release notes</a>.' ), 'http://codex.wordpress.org/Version_3.4.1' ); ?> </p> </div> <div class="changelog"> <h3><?php _e( 'Live Theme Previews' ); ?></h3> <div class="feature-section images-stagger-right"> <img src="<?php echo esc_url( admin_url( 'images/screenshots/theme-customizer.png' ) ); ?>" class="image-50" /> <h4><?php _e( 'Try on New Themes' ); ?></h4> <p><?php _e( 'Gone are the days of rushing to update your header, background, and the like as soon as you activate a new theme. You can now customize these options <strong>before</strong> activating a new theme. Note: this feature is available for installed themes only.' ); ?></p> <h4><?php _e( 'Customize Current Theme' ); ?></h4> <p><?php _e( 'Satisfy your curiosity and try on a fresh coat of paint &mdash; you can also use the live preview mode to customize your current theme. Look for the Customize link on the Themes screen.' ); ?></p> </div> </div> <div class="changelog"> <h3><?php _e( 'Custom Headers' ); ?></h3> <div class="feature-section"> <h4><?php _e( 'Flexible Sizes' ); ?></h4> <p><?php _e( 'You can decide for yourself how tall or wide your custom header image should be. From now on, themes will provide a recommended image size for custom headers rather than a fixed requirement. Note: this feature requires <a href="http://codex.wordpress.org/Custom_Headers">theme support</a>.' ); ?></p> <div class="three-col-images"> <img src="<?php echo esc_url( admin_url( 'images/screenshots/flex-header-1.png' ) ); ?>" class="image-30 first-feature" /> <img src="<?php echo esc_url( admin_url( 'images/screenshots/flex-header-2.png' ) ); ?>" class="image-30" /> <img src="<?php echo esc_url( admin_url( 'images/screenshots/flex-header-3.png' ) ); ?>" class="image-30 last-feature" /> </div> </div> <div class="feature-section images-stagger-right"> <img src="<?php echo esc_url( admin_url( 'images/screenshots/flex-header-media-library.png' ) ); ?>" class="image-50" /> <h4><?php _e( 'Choose from Media Library' ); ?></h4> <p><?php _e( 'Tired of re-uploading the same custom header image every time you check out a new theme? Now you can choose header images from your media library for easier customization.' ); ?></p> </div> </div> <div class="changelog"> <h3><?php _e( 'Twitter Embeds' ); ?></h3> <div class="feature-section images-stagger-right"> <img src="<?php echo esc_url( admin_url( 'images/screenshots/twitter-embed-1.png' ) ); ?>" class="image-30" /> <img src="<?php echo esc_url( admin_url( 'images/screenshots/twitter-embed-2.png' ) ); ?>" class="image-30" /> <h4><?php _e( 'Share Tweets with Style' ); ?></h4> <p><?php _e( 'You can now embed individual tweets in posts. It includes action links that allow readers to reply to, retweet, and favorite the tweet without leaving your site. Just paste a tweet URL on its own line.' ); ?></p> <p><?php printf( __( 'This works with URLs from some other sites, too. For more, see the Codex article on <a href="%s">Embeds</a>.' ), __( 'http://codex.wordpress.org/Embeds' ) ); ?></p> </div> </div> <div class="changelog"> <h3><?php _e( 'Better Captions' ); ?></h3> <div class="feature-section images-stagger-right"> <img src="<?php echo esc_url( admin_url( 'images/screenshots/captions-1.png' ) ); ?>" class="image-30" /> <img src="<?php echo esc_url( admin_url( 'images/screenshots/captions-2.png' ) ); ?>" class="image-30" /> <h4><?php _e( 'HTML Support' ); ?></h4> <p><?php _e( 'Basic HTML support has been added to the caption field in the image uploader. This allows you to add links &mdash; great for photo credits or licensing details &mdash; and basic formatting such as bold and italicized text.' ); ?></p> </div> </div> <div class="changelog"> <h3><?php _e( 'Under the Hood' ); ?></h3> <div class="feature-section three-col"> <div> <h4><?php _e( 'Faster WP_Query' ); ?></h4> <p><?php _e( 'Post queries have been optimized to improve performance, especially for sites with large databases.' ); ?></p> <h4><?php _e( 'Faster Translations' ); ?></h4> <p><?php _e( 'The number of strings loaded on the front end was greatly reduced, resulting in faster front page load times for localized installations.' ); ?> <?php _e( 'Also, better support for East Asian languages, right-to-left languages, theme translations, and more.' ); ?></p> </div> <div> <h4><?php _e( 'Themes API' ); ?></h4> <p><?php _e( 'WP_Theme, wp_get_themes(), wp_get_theme(). Faster, uses less memory, makes use of persistent caching.' ); ?></p> <h4><?php _e( 'Custom Header and Background API' ); ?></h4> <p><?php _e( 'Custom header and background API relocated into the theme support API.' ); ?></p> </div> <div class="last-feature"> <h4><?php _e( 'XML-RPC API' ); ?></h4> <p><?php printf( __( 'A new <a href="%s">WordPress API</a> that supports custom content types and taxonomies, as well as dozens of other bug fixes and improvements.' ), __( 'http://codex.wordpress.org/XML-RPC_WordPress_API' ) ); ?></p> <h4><?php _e( 'External Libraries' ); ?></h4> <p><?php _e( 'jQuery, jQuery UI, TinyMCE, Plupload, PHPMailer, SimplePie, and other libraries were updated. jQuery UI Touch Punch was introduced.' ); ?></p> </div> </div> </div> <div class="return-to-dashboard"> <?php if ( current_user_can( 'update_core' ) && isset( $_GET['updated'] ) ) : ?> <a href="<?php echo esc_url( self_admin_url( 'update-core.php' ) ); ?>"><?php is_multisite() ? _e( 'Return to Updates' ) : _e( 'Return to Dashboard &rarr; Updates' ); ?></a> | <?php endif; ?> <a href="<?php echo esc_url( self_admin_url() ); ?>"><?php is_blog_admin() ? _e( 'Go to Dashboard &rarr; Home' ) : _e( 'Go to Dashboard' ); ?></a> </div> </div> <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); // These are strings we may use to describe maintenance/security releases, where we aim for no new strings. return; _n_noop( 'Maintenance Release', 'Maintenance Releases' ); _n_noop( 'Security Release', 'Security Releases' ); _n_noop( 'Maintenance and Security Release', 'Maintenance and Security Releases' ); /* translators: 1: WordPress version number. */ _n_noop( '<strong>Version %1$s</strong> addressed a security issue.', '<strong>Version %1$s</strong> addressed some security issues.' ); /* translators: 1: WordPress version number, 2: plural number of bugs. */ _n_noop( '<strong>Version %1$s</strong> addressed %2$s bug.', '<strong>Version %1$s</strong> addressed %2$s bugs.' ); /* translators: 1: WordPress version number, 2: plural number of bugs. Singular security issue. */ _n_noop( '<strong>Version %1$s</strong> addressed a security issue and fixed %2$s bug.', '<strong>Version %1$s</strong> addressed a security issue and fixed %2$s bugs.' ); /* translators: 1: WordPress version number, 2: plural number of bugs. More than one security issue. */ _n_noop( '<strong>Version %1$s</strong> addressed some security issues and fixed %2$s bug.', '<strong>Version %1$s</strong> addressed some security issues and fixed %2$s bugs.' ); __( 'For more information, see <a href="%s">the release notes</a>.' );
01happy-blog
trunk/myblog/wp-admin/about.php
PHP
oos
8,636
<?php /** * Widgets administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once( './admin.php' ); /** WordPress Administration Widgets API */ require_once(ABSPATH . 'wp-admin/includes/widgets.php'); if ( ! current_user_can('edit_theme_options') ) wp_die( __( 'Cheatin&#8217; uh?' )); $widgets_access = get_user_setting( 'widgets_access' ); if ( isset($_GET['widgets-access']) ) { $widgets_access = 'on' == $_GET['widgets-access'] ? 'on' : 'off'; set_user_setting( 'widgets_access', $widgets_access ); } function wp_widgets_access_body_class($classes) { return "$classes widgets_access "; } if ( 'on' == $widgets_access ) { add_filter( 'admin_body_class', 'wp_widgets_access_body_class' ); } else { wp_enqueue_script('admin-widgets'); if ( wp_is_mobile() ) wp_enqueue_script( 'jquery-touch-punch' ); } do_action( 'sidebar_admin_setup' ); $title = __( 'Widgets' ); $parent_file = 'themes.php'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('Widgets are independent sections of content that can be placed into any widgetized area provided by your theme (commonly called sidebars). To populate your sidebars/widget areas with individual widgets, drag and drop the title bars into the desired area. By default, only the first widget area is expanded. To populate additional widget areas, click on their title bars to expand them.') . '</p> <p>' . __('The Available Widgets section contains all the widgets you can choose from. Once you drag a widget into a sidebar, it will open to allow you to configure its settings. When you are happy with the widget settings, click the Save button and the widget will go live on your site. If you click Delete, it will remove the widget.') . '</p>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'removing-reusing', 'title' => __('Removing and Reusing'), 'content' => '<p>' . __('If you want to remove the widget but save its setting for possible future use, just drag it into the Inactive Widgets area. You can add them back anytime from there. This is especially helpful when you switch to a theme with fewer or different widget areas.') . '</p> <p>' . __('Widgets may be used multiple times. You can give each widget a title, to display on your site, but it&#8217;s not required.') . '</p> <p>' . __('Enabling Accessibility Mode, via Screen Options, allows you to use Add and Edit buttons instead of using drag and drop.') . '</p>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'missing-widgets', 'title' => __('Missing Widgets'), 'content' => '<p>' . __('Many themes show some sidebar widgets by default until you edit your sidebars, but they are not automatically displayed in your sidebar management tool. After you make your first widget change, you can re-add the default widgets by adding them from the Available Widgets area.') . '</p>' . '<p>' . __('When changing themes, there is often some variation in the number and setup of widget areas/sidebars and sometimes these conflicts make the transition a bit less smooth. If you changed themes and seem to be missing widgets, scroll down on this screen to the Inactive area, where all your widgets and their settings will have been saved.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Widgets_Screen" target="_blank">Documentation on Widgets</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); if ( empty($wp_registered_sidebars) ) { // the theme has no sidebars, die. require_once( './admin-header.php' ); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <div class="error"> <p><?php _e( 'No Sidebars Defined' ); ?></p> </div> <p><?php _e( 'The theme you are currently using isn&#8217;t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="http://codex.wordpress.org/Widgetizing_Themes">follow these instructions</a>.' ); ?></p> </div> <?php require_once( './admin-footer.php' ); exit; } // These are the widgets grouped by sidebar $sidebars_widgets = wp_get_sidebars_widgets(); if ( empty( $sidebars_widgets ) ) $sidebars_widgets = wp_get_widget_defaults(); foreach ( $sidebars_widgets as $sidebar_id => $widgets ) { if ( 'wp_inactive_widgets' == $sidebar_id ) continue; if ( !isset( $wp_registered_sidebars[ $sidebar_id ] ) ) { if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar register_sidebar(array( 'name' => __( 'Inactive Sidebar (not used)' ), 'id' => $sidebar_id, 'class' => 'inactive-sidebar orphan-sidebar', 'description' => __( 'This sidebar is no longer available and does not show anywhere on your site. Remove each of the widgets below to fully remove this inactive sidebar.' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', )); } else { unset( $sidebars_widgets[ $sidebar_id ] ); } } } // register the inactive_widgets area as sidebar register_sidebar(array( 'name' => __('Inactive Widgets'), 'id' => 'wp_inactive_widgets', 'class' => 'inactive-sidebar', 'description' => __( 'Drag widgets here to remove them from the sidebar but keep their settings.' ), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', )); retrieve_widgets(); // We're saving a widget without js if ( isset($_POST['savewidget']) || isset($_POST['removewidget']) ) { $widget_id = $_POST['widget-id']; check_admin_referer("save-delete-widget-$widget_id"); $number = isset($_POST['multi_number']) ? (int) $_POST['multi_number'] : ''; if ( $number ) { foreach ( $_POST as $key => $val ) { if ( is_array($val) && preg_match('/__i__|%i%/', key($val)) ) { $_POST[$key] = array( $number => array_shift($val) ); break; } } } $sidebar_id = $_POST['sidebar']; $position = isset($_POST[$sidebar_id . '_position']) ? (int) $_POST[$sidebar_id . '_position'] - 1 : 0; $id_base = $_POST['id_base']; $sidebar = isset($sidebars_widgets[$sidebar_id]) ? $sidebars_widgets[$sidebar_id] : array(); // delete if ( isset($_POST['removewidget']) && $_POST['removewidget'] ) { if ( !in_array($widget_id, $sidebar, true) ) { wp_redirect( admin_url('widgets.php?error=0') ); exit; } $sidebar = array_diff( $sidebar, array($widget_id) ); $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1'); } $_POST['widget-id'] = $sidebar; foreach ( (array) $wp_registered_widget_updates as $name => $control ) { if ( $name != $id_base || !is_callable($control['callback']) ) continue; ob_start(); call_user_func_array( $control['callback'], $control['params'] ); ob_end_clean(); break; } $sidebars_widgets[$sidebar_id] = $sidebar; // remove old position if ( !isset($_POST['delete_widget']) ) { foreach ( $sidebars_widgets as $key => $sb ) { if ( is_array($sb) ) $sidebars_widgets[$key] = array_diff( $sb, array($widget_id) ); } array_splice( $sidebars_widgets[$sidebar_id], $position, 0, $widget_id ); } wp_set_sidebars_widgets($sidebars_widgets); wp_redirect( admin_url('widgets.php?message=0') ); exit; } // Output the widget form without js if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) { $widget_id = $_GET['editwidget']; if ( isset($_GET['addnew']) ) { // Default to the first sidebar $sidebar = array_shift( $keys = array_keys($wp_registered_sidebars) ); if ( isset($_GET['base']) && isset($_GET['num']) ) { // multi-widget // Copy minimal info from an existing instance of this widget to a new instance foreach ( $wp_registered_widget_controls as $control ) { if ( $_GET['base'] === $control['id_base'] ) { $control_callback = $control['callback']; $multi_number = (int) $_GET['num']; $control['params'][0]['number'] = -1; $widget_id = $control['id'] = $control['id_base'] . '-' . $multi_number; $wp_registered_widget_controls[$control['id']] = $control; break; } } } } if ( isset($wp_registered_widget_controls[$widget_id]) && !isset($control) ) { $control = $wp_registered_widget_controls[$widget_id]; $control_callback = $control['callback']; } elseif ( !isset($wp_registered_widget_controls[$widget_id]) && isset($wp_registered_widgets[$widget_id]) ) { $name = esc_html( strip_tags($wp_registered_widgets[$widget_id]['name']) ); } if ( !isset($name) ) $name = esc_html( strip_tags($control['name']) ); if ( !isset($sidebar) ) $sidebar = isset($_GET['sidebar']) ? $_GET['sidebar'] : 'wp_inactive_widgets'; if ( !isset($multi_number) ) $multi_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : ''; $id_base = isset($control['id_base']) ? $control['id_base'] : $control['id']; // show the widget form $width = ' style="width:' . max($control['width'], 350) . 'px"'; $key = isset($_GET['key']) ? (int) $_GET['key'] : 0; require_once( './admin-header.php' ); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <div class="editwidget"<?php echo $width; ?>> <h3><?php printf( __( 'Widget %s' ), $name ); ?></h3> <form action="widgets.php" method="post"> <div class="widget-inside"> <?php if ( is_callable( $control_callback ) ) call_user_func_array( $control_callback, $control['params'] ); else echo '<p>' . __('There are no options for this widget.') . "</p>\n"; ?> </div> <p class="describe"><?php _e('Select both the sidebar for this widget and the position of the widget in that sidebar.'); ?></p> <div class="widget-position"> <table class="widefat"><thead><tr><th><?php _e('Sidebar'); ?></th><th><?php _e('Position'); ?></th></tr></thead><tbody> <?php foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) { echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr($sbname) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>"; if ( 'wp_inactive_widgets' == $sbname || 'orphaned_widgets' == substr( $sbname, 0, 16 ) ) { echo '&nbsp;'; } else { if ( !isset($sidebars_widgets[$sbname]) || !is_array($sidebars_widgets[$sbname]) ) { $j = 1; $sidebars_widgets[$sbname] = array(); } else { $j = count($sidebars_widgets[$sbname]); if ( isset($_GET['addnew']) || !in_array($widget_id, $sidebars_widgets[$sbname], true) ) $j++; } $selected = ''; echo "\t\t<select name='{$sbname}_position'>\n"; echo "\t\t<option value=''>" . __('&mdash; Select &mdash;') . "</option>\n"; for ( $i = 1; $i <= $j; $i++ ) { if ( in_array($widget_id, $sidebars_widgets[$sbname], true) ) $selected = selected( $i, $key + 1, false ); echo "\t\t<option value='$i'$selected> $i </option>\n"; } echo "\t\t</select>\n"; } echo "</td></tr>\n"; } ?> </tbody></table> </div> <div class="widget-control-actions"> <?php if ( isset($_GET['addnew']) ) { ?> <a href="widgets.php" class="button alignleft"><?php _e('Cancel'); ?></a> <?php } else { submit_button( __( 'Delete' ), 'button alignleft', 'removewidget', false ); } submit_button( __( 'Save Widget' ), 'button-primary alignright', 'savewidget', false ); ?> <input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($widget_id); ?>" /> <input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" /> <input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" /> <?php wp_nonce_field("save-delete-widget-$widget_id"); ?> <br class="clear" /> </div> </form> </div> </div> <?php require_once( './admin-footer.php' ); exit; } $messages = array( __('Changes saved.') ); $errors = array( __('Error while saving.'), __('Error in displaying the widget settings form.') ); require_once( './admin-header.php' ); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <?php if ( isset($_GET['message']) && isset($messages[$_GET['message']]) ) { ?> <div id="message" class="updated"><p><?php echo $messages[$_GET['message']]; ?></p></div> <?php } ?> <?php if ( isset($_GET['error']) && isset($errors[$_GET['error']]) ) { ?> <div id="message" class="error"><p><?php echo $errors[$_GET['error']]; ?></p></div> <?php } ?> <?php do_action( 'widgets_admin_page' ); ?> <div class="widget-liquid-left"> <div id="widgets-left"> <div id="available-widgets" class="widgets-holder-wrap"> <div class="sidebar-name"> <div class="sidebar-name-arrow"><br /></div> <h3><?php _e('Available Widgets'); ?> <span id="removing-widget"><?php _ex('Deactivate', 'removing-widget'); ?> <span></span></span></h3></div> <div class="widget-holder"> <p class="description"><?php _e('Drag widgets from here to a sidebar on the right to activate them. Drag widgets back here to deactivate them and delete their settings.'); ?></p> <div id="widget-list"> <?php wp_list_widgets(); ?> </div> <br class='clear' /> </div> <br class="clear" /> </div> <?php foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) { $wrap_class = 'widgets-holder-wrap'; if ( !empty( $registered_sidebar['class'] ) ) $wrap_class .= ' ' . $registered_sidebar['class']; ?> <div class="<?php echo esc_attr( $wrap_class ); ?>"> <div class="sidebar-name"> <div class="sidebar-name-arrow"><br /></div> <h3><?php echo esc_html( $registered_sidebar['name'] ); ?> <span><img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-feedback" title="" alt="" /></span> </h3> </div> <div class="widget-holder inactive"> <?php wp_list_widget_controls( $registered_sidebar['id'] ); ?> <br class="clear" /> </div> </div> <?php } } ?> </div> </div> <div class="widget-liquid-right"> <div id="widgets-right"> <?php $i = 0; foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) continue; $wrap_class = 'widgets-holder-wrap'; if ( !empty( $registered_sidebar['class'] ) ) $wrap_class .= ' sidebar-' . $registered_sidebar['class']; if ( $i ) $wrap_class .= ' closed'; ?> <div class="<?php echo esc_attr( $wrap_class ); ?>"> <div class="sidebar-name"> <div class="sidebar-name-arrow"><br /></div> <h3><?php echo esc_html( $registered_sidebar['name'] ); ?> <span><img src="<?php echo esc_url( admin_url( 'images/wpspin_dark.gif' ) ); ?>" class="ajax-feedback" title="" alt="" /></span></h3></div> <?php wp_list_widget_controls( $sidebar ); // Show the control forms for each of the widgets in this sidebar ?> </div> <?php $i++; } ?> </div> </div> <form action="" method="post"> <?php wp_nonce_field( 'save-sidebar-widgets', '_wpnonce_widgets', false ); ?> </form> <br class="clear" /> </div> <?php do_action( 'sidebar_admin_page' ); require_once( './admin-footer.php' );
01happy-blog
trunk/myblog/wp-admin/widgets.php
PHP
oos
15,457
<?php /** * Comment Management Screen * * @package WordPress * @subpackage Administration */ /** Load WordPress Bootstrap */ require_once('./admin.php'); $parent_file = 'edit-comments.php'; $submenu_file = 'edit-comments.php'; wp_reset_vars( array('action') ); if ( isset( $_POST['deletecomment'] ) ) $action = 'deletecomment'; if ( 'cdc' == $action ) $action = 'delete'; elseif ( 'mac' == $action ) $action = 'approve'; if ( isset( $_GET['dt'] ) ) { if ( 'spam' == $_GET['dt'] ) $action = 'spam'; elseif ( 'trash' == $_GET['dt'] ) $action = 'trash'; } /** * Display error message at bottom of comments. * * @param string $msg Error Message. Assumed to contain HTML and be sanitized. */ function comment_footer_die( $msg ) { echo "<div class='wrap'><p>$msg</p></div>"; include('./admin-footer.php'); die; } switch( $action ) { case 'editcomment' : $title = __('Edit Comment'); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __( 'You can edit the information left in a comment if needed. This is often useful when you notice that a commenter has made a typographical error.' ) . '</p>' . '<p>' . __( 'You can also moderate the comment from this screen using the Status box, where you can also change the timestamp of the comment.' ) . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . '<p>' . __( '<a href="http://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' . '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' ); wp_enqueue_script('comment'); require_once('./admin-header.php'); $comment_id = absint( $_GET['c'] ); if ( !$comment = get_comment( $comment_id ) ) comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'javascript:history.go(-1)') ); if ( !current_user_can( 'edit_comment', $comment_id ) ) comment_footer_die( __('You are not allowed to edit this comment.') ); if ( 'trash' == $comment->comment_approved ) comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') ); $comment = get_comment_to_edit( $comment_id ); include('./edit-form-comment.php'); break; case 'delete' : case 'approve' : case 'trash' : case 'spam' : $title = __('Moderate Comment'); $comment_id = absint( $_GET['c'] ); if ( !$comment = get_comment_to_edit( $comment_id ) ) { wp_redirect( admin_url('edit-comments.php?error=1') ); die(); } if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) { wp_redirect( admin_url('edit-comments.php?error=2') ); die(); } // No need to re-approve/re-trash/re-spam a comment. if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) { wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) ); die(); } require_once('./admin-header.php'); $formaction = $action . 'comment'; $nonce_action = 'approve' == $action ? 'approve-comment_' : 'delete-comment_'; $nonce_action .= $comment_id; ?> <div class='wrap'> <div class="narrow"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <?php switch ( $action ) { case 'spam' : $caution_msg = __('You are about to mark the following comment as spam:'); $button = __('Spam Comment'); break; case 'trash' : $caution_msg = __('You are about to move the following comment to the Trash:'); $button = __('Trash Comment'); break; case 'delete' : $caution_msg = __('You are about to delete the following comment:'); $button = __('Permanently Delete Comment'); break; default : $caution_msg = __('You are about to approve the following comment:'); $button = __('Approve Comment'); break; } if ( $comment->comment_approved != '0' ) { // if not unapproved $message = ''; switch ( $comment->comment_approved ) { case '1' : $message = __('This comment is currently approved.'); break; case 'spam' : $message = __('This comment is currently marked as spam.'); break; case 'trash' : $message = __('This comment is currently in the Trash.'); break; } if ( $message ) echo '<div class="updated"><p>' . $message . '</p></div>'; } ?> <p><strong><?php _e('Caution:'); ?></strong> <?php echo $caution_msg; ?></p> <table class="form-table comment-ays"> <tr class="alt"> <th scope="row"><?php _e('Author'); ?></th> <td><?php echo $comment->comment_author; ?></td> </tr> <?php if ( $comment->comment_author_email ) { ?> <tr> <th scope="row"><?php _e('E-mail'); ?></th> <td><?php echo $comment->comment_author_email; ?></td> </tr> <?php } ?> <?php if ( $comment->comment_author_url ) { ?> <tr> <th scope="row"><?php _e('URL'); ?></th> <td><a href="<?php echo $comment->comment_author_url; ?>"><?php echo $comment->comment_author_url; ?></a></td> </tr> <?php } ?> <tr> <th scope="row" valign="top"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th> <td><?php echo $comment->comment_content; ?></td> </tr> </table> <p><?php _e('Are you sure you want to do this?'); ?></p> <form action='comment.php' method='get'> <table width="100%"> <tr> <td><a class="button" href="<?php echo admin_url('edit-comments.php'); ?>"><?php esc_attr_e('No'); ?></a></td> <td class="textright"><?php submit_button( $button, 'button' ); ?></td> </tr> </table> <?php wp_nonce_field( $nonce_action ); ?> <input type='hidden' name='action' value='<?php echo esc_attr($formaction); ?>' /> <input type='hidden' name='c' value='<?php echo esc_attr($comment->comment_ID); ?>' /> <input type='hidden' name='noredir' value='1' /> </form> </div> </div> <?php break; case 'deletecomment' : case 'trashcomment' : case 'untrashcomment' : case 'spamcomment' : case 'unspamcomment' : case 'approvecomment' : case 'unapprovecomment' : $comment_id = absint( $_REQUEST['c'] ); if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) check_admin_referer( 'approve-comment_' . $comment_id ); else check_admin_referer( 'delete-comment_' . $comment_id ); $noredir = isset($_REQUEST['noredir']); if ( !$comment = get_comment($comment_id) ) comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'edit-comments.php') ); if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) comment_footer_die( __('You are not allowed to edit comments on this post.') ); if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') ) $redir = wp_get_referer(); elseif ( '' != wp_get_original_referer() && ! $noredir ) $redir = wp_get_original_referer(); elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) $redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) ); else $redir = admin_url('edit-comments.php'); $redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir ); switch ( $action ) { case 'deletecomment' : wp_delete_comment( $comment_id ); $redir = add_query_arg( array('deleted' => '1'), $redir ); break; case 'trashcomment' : wp_trash_comment($comment_id); $redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir ); break; case 'untrashcomment' : wp_untrash_comment($comment_id); $redir = add_query_arg( array('untrashed' => '1'), $redir ); break; case 'spamcomment' : wp_spam_comment($comment_id); $redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir ); break; case 'unspamcomment' : wp_unspam_comment($comment_id); $redir = add_query_arg( array('unspammed' => '1'), $redir ); break; case 'approvecomment' : wp_set_comment_status( $comment_id, 'approve' ); $redir = add_query_arg( array( 'approved' => 1 ), $redir ); break; case 'unapprovecomment' : wp_set_comment_status( $comment_id, 'hold' ); $redir = add_query_arg( array( 'unapproved' => 1 ), $redir ); break; } wp_redirect( $redir ); die; break; case 'editedcomment' : $comment_id = absint( $_POST['comment_ID'] ); $comment_post_id = absint( $_POST['comment_post_ID'] ); check_admin_referer( 'update-comment_' . $comment_id ); edit_comment(); $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id; $location = apply_filters( 'comment_edit_redirect', $location, $comment_id ); wp_redirect( $location ); exit(); break; default: wp_die( __('Unknown action.') ); break; } // end switch include('./admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/comment.php
PHP
oos
8,846
<?php /** * Privacy Options Settings Administration Screen. * * @package WordPress * @subpackage Administration */ /** Load WordPress Administration Bootstrap */ require_once('./admin.php'); if ( ! current_user_can( 'manage_options' ) ) wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) ); $title = __('Privacy Settings'); $parent_file = 'options-general.php'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('You can choose whether or not your site will be crawled by robots, ping services, and spiders. If you want those services to ignore your site, click the radio button next to &#8220;Ask search engines not to index this site&#8221; and click the Save Changes button at the bottom of the screen. Note that your privacy is not complete; your site is still visible on the web.') . '</p>' . '<p>' . __('When this setting is in effect a reminder is shown in the Right Now box of the Dashboard that says, &#8220;Search Engines Blocked,&#8221; to remind you that your site is not being crawled.') . '</p>', ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Settings_Privacy_Screen" target="_blank">Documentation on Privacy Settings</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); include('./admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <form method="post" action="options.php"> <?php settings_fields('privacy'); ?> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e( 'Site Visibility' ); ?> </th> <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Site Visibility' ); ?> </span></legend> <input id="blog-public" type="radio" name="blog_public" value="1" <?php checked('1', get_option('blog_public')); ?> /> <label for="blog-public"><?php _e( 'Allow search engines to index this site.' );?></label><br/> <input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked('0', get_option('blog_public')); ?> /> <label for="blog-norobots"><?php _e( 'Ask search engines not to index this site.' ); ?></label> <p class="description"><?php _e( 'Note: Neither of these options blocks access to your site &mdash; it is up to search engines to honor your request.' ); ?></p> <?php do_action('blog_privacy_selector'); ?> </fieldset></td> </tr> <?php do_settings_fields('privacy', 'default'); ?> </table> <?php do_settings_sections('privacy'); ?> <?php submit_button(); ?> </form> </div> <?php include('./admin-footer.php') ?>
01happy-blog
trunk/myblog/wp-admin/options-privacy.php
PHP
oos
2,745
<?php /** * User Dashboard About administration panel. * * @package WordPress * @subpackage Administration * @since 3.4.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); require( '../about.php' );
01happy-blog
trunk/myblog/wp-admin/user/about.php
PHP
oos
237
<?php /** * Build User Administration Menu. * * @package WordPress * @subpackage Administration * @since 3.1.0 */ $menu[2] = array(__('Dashboard'), 'exist', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'div'); $menu[4] = array( '', 'exist', 'separator1', '', 'wp-menu-separator' ); $menu[70] = array( __('Profile'), 'exist', 'profile.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' ); $menu[99] = array( '', 'exist', 'separator-last', '', 'wp-menu-separator-last' ); $_wp_real_parent_file['users.php'] = 'profile.php'; $compat = array(); $submenu = array(); require_once(ABSPATH . 'wp-admin/includes/menu.php');
01happy-blog
trunk/myblog/wp-admin/user/menu.php
PHP
oos
671
<?php /** * User Dashboard Freedoms administration panel. * * @package WordPress * @subpackage Administration * @since 3.4.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); require( '../freedoms.php' );
01happy-blog
trunk/myblog/wp-admin/user/freedoms.php
PHP
oos
243
<?php /** * Edit user administration panel. * * @package WordPress * @subpackage Administration * @since 3.1.0 */ require_once( './admin.php' ); require( '../user-edit.php' );
01happy-blog
trunk/myblog/wp-admin/user/user-edit.php
PHP
oos
183
<?php /** * User Dashboard Administration Screen * * @package WordPress * @subpackage Administration * @since 3.1.0 */ require_once( './admin.php' ); require( '../index.php' );
01happy-blog
trunk/myblog/wp-admin/user/index.php
PHP
oos
185
<?php /** * User Profile Administration Screen. * * @package WordPress * @subpackage Administration * @since 3.1.0 */ require_once( './admin.php' ); require( '../profile.php' );
01happy-blog
trunk/myblog/wp-admin/user/profile.php
PHP
oos
185
<?php /** * User Dashboard Credits administration panel. * * @package WordPress * @subpackage Administration * @since 3.4.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); require( '../credits.php' );
01happy-blog
trunk/myblog/wp-admin/user/credits.php
PHP
oos
241
<?php /** * WordPress User Administration Bootstrap * * @package WordPress * @subpackage Administration * @since 3.1.0 */ define('WP_USER_ADMIN', true); require_once( dirname(dirname(__FILE__)) . '/admin.php'); if ( ! is_multisite() ) { wp_redirect( admin_url() ); exit; } $redirect_user_admin_request = ( ( $current_blog->domain != $current_site->domain ) || ( $current_blog->path != $current_site->path ) ); $redirect_user_admin_request = apply_filters( 'redirect_user_admin_request', $redirect_user_admin_request ); if ( $redirect_user_admin_request ) { wp_redirect( user_admin_url() ); exit; } unset( $redirect_user_admin_request );
01happy-blog
trunk/myblog/wp-admin/user/admin.php
PHP
oos
651
<?php /** * Post advanced form for inclusion in the administration panels. * * @package WordPress * @subpackage Administration */ // don't load directly if ( !defined('ABSPATH') ) die('-1'); wp_enqueue_script('post'); if ( wp_is_mobile() ) wp_enqueue_script( 'jquery-touch-punch' ); if ( post_type_supports($post_type, 'editor') || post_type_supports($post_type, 'thumbnail') ) { add_thickbox(); wp_enqueue_script('media-upload'); } /** * Post ID global * @name $post_ID * @var int */ $post_ID = isset($post_ID) ? (int) $post_ID : 0; $user_ID = isset($user_ID) ? (int) $user_ID : 0; $action = isset($action) ? $action : ''; $messages = array(); $messages['post'] = array( 0 => '', // Unused. Messages start at index 1. 1 => sprintf( __('Post updated. <a href="%s">View post</a>'), esc_url( get_permalink($post_ID) ) ), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Post updated.'), /* translators: %s: date and time of the revision */ 5 => isset($_GET['revision']) ? sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __('Post published. <a href="%s">View post</a>'), esc_url( get_permalink($post_ID) ) ), 7 => __('Post saved.'), 8 => sprintf( __('Post submitted. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 9 => sprintf( __('Post scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview post</a>'), // translators: Publish box date format, see http://php.net/date date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), ); $messages['page'] = array( 0 => '', // Unused. Messages start at index 1. 1 => sprintf( __('Page updated. <a href="%s">View page</a>'), esc_url( get_permalink($post_ID) ) ), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Page updated.'), 5 => isset($_GET['revision']) ? sprintf( __('Page restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __('Page published. <a href="%s">View page</a>'), esc_url( get_permalink($post_ID) ) ), 7 => __('Page saved.'), 8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), ); $messages = apply_filters( 'post_updated_messages', $messages ); $message = false; if ( isset($_GET['message']) ) { $_GET['message'] = absint( $_GET['message'] ); if ( isset($messages[$post_type][$_GET['message']]) ) $message = $messages[$post_type][$_GET['message']]; elseif ( !isset($messages[$post_type]) && isset($messages['post'][$_GET['message']]) ) $message = $messages['post'][$_GET['message']]; } $notice = false; $form_extra = ''; if ( 'auto-draft' == $post->post_status ) { if ( 'edit' == $action ) $post->post_title = ''; $autosave = false; $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />"; } else { $autosave = wp_get_post_autosave( $post_ID ); } $form_action = 'editpost'; $nonce_action = 'update-' . $post_type . '_' . $post_ID; $form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($post_ID) . "' />"; // Detect if there exists an autosave newer than the post and if that autosave is different than the post if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) { foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) { if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) { $notice = sprintf( __( 'There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>' ), get_edit_post_link( $autosave->ID ) ); break; } } unset($autosave_field, $_autosave_field); } $post_type_object = get_post_type_object($post_type); // All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action). require_once('./includes/meta-boxes.php'); add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core'); if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' ); // all taxonomies foreach ( get_object_taxonomies($post_type) as $tax_name ) { $taxonomy = get_taxonomy($tax_name); if ( ! $taxonomy->show_ui ) continue; $label = $taxonomy->labels->name; if ( !is_taxonomy_hierarchical($tax_name) ) add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name )); else add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name )); } if ( post_type_supports($post_type, 'page-attributes') ) add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) ) add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); if ( post_type_supports($post_type, 'excerpt') ) add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core'); if ( post_type_supports($post_type, 'trackbacks') ) add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', null, 'normal', 'core'); if ( post_type_supports($post_type, 'custom-fields') ) add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', null, 'normal', 'core'); do_action('dbx_post_advanced'); if ( post_type_supports($post_type, 'comments') ) add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core'); if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') ) add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core'); if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core'); if ( post_type_supports($post_type, 'author') ) { if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core'); } if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); do_action('add_meta_boxes', $post_type, $post); do_action('add_meta_boxes_' . $post_type, $post); do_action('do_meta_boxes', $post_type, 'normal', $post); do_action('do_meta_boxes', $post_type, 'advanced', $post); do_action('do_meta_boxes', $post_type, 'side', $post); add_screen_option('layout_columns', array('max' => 2, 'default' => 2) ); if ( 'post' == $post_type ) { $customize_display = '<p>' . __('The title field and the big Post Editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'customize-display', 'title' => __('Customizing This Display'), 'content' => $customize_display, ) ); $title_and_editor = '<p>' . __('<strong>Title</strong> - Enter a title for your post. After you enter a title, you&#8217;ll see the permalink below, which you can edit.') . '</p>'; $title_and_editor .= '<p>' . __('<strong>Post editor</strong> - Enter the text for your post. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The HTML mode allows you to enter raw HTML along with your post text. You can insert media files by clicking the icons above the post editor and following the directions. You can go to the distraction-free writing screen via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular post editor.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'title-post-editor', 'title' => __('Title and Post Editor'), 'content' => $title_and_editor, ) ); $publish_box = '<p>' . __('<strong>Publish</strong> - You can set the terms of publishing your post in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a post or making it stay at the top of your blog indefinitely (sticky). Publish (immediately) allows you to set a future or past date and time, so you can schedule a post to be published in the future or backdate a post.') . '</p>'; if ( current_theme_supports( 'post-formats' ) && post_type_supports( 'post', 'post-formats' ) ) { $publish_box .= '<p>' . __( '<strong>Post Format</strong> - This designates how your theme will display a specific post. For example, you could have a <em>standard</em> blog post with a title and paragraphs, or a short <em>aside</em> that omits the title and contains a short text blurb. Please refer to the Codex for <a href="http://codex.wordpress.org/Post_Formats#Supported_Formats">descriptions of each post format</a>. Your theme could enable all or some of 10 possible formats.' ) . '</p>'; } if ( current_theme_supports( 'post-thumbnails' ) && post_type_supports( 'post', 'thumbnail' ) ) { $publish_box .= '<p>' . __('<strong>Featured Image</strong> - This allows you to associate an image with your post without inserting it. This is usually useful only if your theme makes use of the featured image as a post thumbnail on the home page, a custom header, etc.') . '</p>'; } get_current_screen()->add_help_tab( array( 'id' => 'publish-box', 'title' => __('Publish Box'), 'content' => $publish_box, ) ); $discussion_settings = '<p>' . __('<strong>Send Trackbacks</strong> - Trackbacks are a way to notify legacy blog systems that you&#8217;ve linked to them. Enter the URL(s) you want to send trackbacks. If you link to other WordPress sites they&#8217;ll be notified automatically using pingbacks, and this field is unnecessary.') . '</p>'; $discussion_settings .= '<p>' . __('<strong>Discussion</strong> - You can turn comments and pings on or off, and if there are comments on the post, you can see them here and moderate them.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'discussion-settings', 'title' => __('Discussion Settings'), 'content' => $discussion_settings, ) ); get_current_screen()->set_help_sidebar( '<p>' . sprintf(__('You can also create posts with the <a href="%s">Press This bookmarklet</a>.'), 'options-writing.php') . '</p>' . '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Posts_Add_New_Screen" target="_blank">Documentation on Writing and Editing Posts</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); } elseif ( 'page' == $post_type ) { $about_pages = '<p>' . __('Pages are similar to Posts in that they have a title, body text, and associated metadata, but they are different in that they are not part of the chronological blog stream, kind of like permanent posts. Pages are not categorized or tagged, but can have a hierarchy. You can nest Pages under other Pages by making one the &#8220;Parent&#8221; of the other, creating a group of Pages.') . '</p>' . '<p>' . __('Creating a Page is very similar to creating a Post, and the screens can be customized in the same way using drag and drop, the Screen Options tab, and expanding/collapsing boxes as you choose. This screen also has the distraction-free writing space, available in both the Visual and HTML modes via the Fullscreen buttons. The Page editor mostly works the same as the Post editor, but there are some Page-specific features in the Page Attributes box:') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'about-pages', 'title' => __('About Pages'), 'content' => $about_pages, ) ); $page_attributes = '<p>' . __('<strong>Parent</strong> - You can arrange your pages in hierarchies. For example, you could have an &#8220;About&#8221; page that has &#8220;Life Story&#8221; and &#8220;My Dog&#8221; pages under it. There are no limits to how many levels you can nest pages.') . '</p>' . '<p>' . __('<strong>Template</strong> - Some themes have custom templates you can use for certain pages that might have additional features or custom layouts. If so, you&#8217;ll see them in this dropdown menu.') . '</p>' . '<p>' . __('<strong>Order</strong> - Pages are usually ordered alphabetically, but you can choose your own order by entering a number (1 for first, etc.) in this field.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'page-attributes', 'title' => __('Page Attributes'), 'content' => $page_attributes, ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Pages_Add_New_Screen" target="_blank">Documentation on Adding New Pages</a>') . '</p>' . '<p>' . __('<a href="http://codex.wordpress.org/Pages_Screen#Editing_Individual_Pages" target="_blank">Documentation on Editing Pages</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); } require_once('./admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?><?php if ( isset( $post_new_file ) ) : ?> <a href="<?php echo esc_url( $post_new_file ) ?>" class="add-new-h2"><?php echo esc_html($post_type_object->labels->add_new); ?></a><?php endif; ?></h2> <?php if ( $notice ) : ?> <div id="notice" class="error"><p><?php echo $notice ?></p></div> <?php endif; ?> <?php if ( $message ) : ?> <div id="message" class="updated"><p><?php echo $message; ?></p></div> <?php endif; ?> <form name="post" action="post.php" method="post" id="post"<?php do_action('post_edit_form_tag'); ?>> <?php wp_nonce_field($nonce_action); ?> <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" /> <input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ) ?>" /> <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ) ?>" /> <input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" /> <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post_type ) ?>" /> <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status) ?>" /> <input type="hidden" id="referredby" name="referredby" value="<?php echo esc_url(stripslashes(wp_get_referer())); ?>" /> <?php if ( ! empty( $active_post_lock ) ) { ?> <input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" /> <?php } if ( 'draft' != $post->post_status ) wp_original_referer_field(true, 'previous'); echo $form_extra; wp_nonce_field( 'autosave', 'autosavenonce', false ); wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> <div id="poststuff"> <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> <div id="post-body-content"> <?php if ( post_type_supports($post_type, 'title') ) { ?> <div id="titlediv"> <div id="titlewrap"> <label class="hide-if-no-js" style="visibility:hidden" id="title-prompt-text" for="title"><?php echo apply_filters( 'enter_title_here', __( 'Enter title here' ), $post ); ?></label> <input type="text" name="post_title" size="30" tabindex="1" value="<?php echo esc_attr( htmlspecialchars( $post->post_title ) ); ?>" id="title" autocomplete="off" /> </div> <div class="inside"> <?php $sample_permalink_html = $post_type_object->public ? get_sample_permalink_html($post->ID) : ''; $shortlink = wp_get_shortlink($post->ID, 'post'); if ( !empty($shortlink) ) $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>'; if ( $post_type_object->public && ! ( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?> <div id="edit-slug-box"> <?php if ( ! empty($post->ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status ) echo $sample_permalink_html; ?> </div> <?php } ?> </div> <?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?> </div> <?php } ?> <?php if ( post_type_supports($post_type, 'editor') ) { ?> <div id="postdivrich" class="postarea"> <?php wp_editor($post->post_content, 'content', array('dfw' => true, 'tabindex' => 1) ); ?> <table id="post-status-info" cellspacing="0"><tbody><tr> <td id="wp-word-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></td> <td class="autosave-info"> <span class="autosave-message">&nbsp;</span> <?php if ( 'auto-draft' != $post->post_status ) { echo '<span id="last-edit">'; if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) { $last_user = get_userdata($last_id); printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified)); } else { printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified)); } echo '</span>'; } ?> </td> </tr></tbody></table> </div> <?php } ?> </div><!-- /post-body-content --> <div id="postbox-container-1" class="postbox-container"> <?php if ( 'page' == $post_type ) do_action('submitpage_box'); else do_action('submitpost_box'); do_meta_boxes($post_type, 'side', $post); ?> </div> <div id="postbox-container-2" class="postbox-container"> <?php do_meta_boxes(null, 'normal', $post); if ( 'page' == $post_type ) do_action('edit_page_form'); else do_action('edit_form_advanced'); do_meta_boxes(null, 'advanced', $post); ?> </div> <?php do_action('dbx_post_sidebar'); ?> </div><!-- /post-body --> <br class="clear" /> </div><!-- /poststuff --> </form> </div> <?php if ( post_type_supports( $post_type, 'comments' ) ) wp_comment_reply(); ?> <?php if ((isset($post->post_title) && '' == $post->post_title) || (isset($_GET['message']) && 2 > $_GET['message'])) : ?> <script type="text/javascript"> try{document.post.title.focus();}catch(e){} </script> <?php endif; ?>
01happy-blog
trunk/myblog/wp-admin/edit-form-advanced.php
PHP
oos
20,363
<?php /** * Update/Install Plugin/Theme administration panel. * * @package WordPress * @subpackage Administration */ if ( ! defined( 'IFRAME_REQUEST' ) && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ) ) ) define( 'IFRAME_REQUEST', true ); /** WordPress Administration Bootstrap */ require_once('./admin.php'); include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; if ( isset($_GET['action']) ) { $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : ''; $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : ''; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; if ( 'update-selected' == $action ) { if ( ! current_user_can( 'update_plugins' ) ) wp_die( __( 'You do not have sufficient permissions to update plugins for this site.' ) ); check_admin_referer( 'bulk-update-plugins' ); if ( isset( $_GET['plugins'] ) ) $plugins = explode( ',', stripslashes($_GET['plugins']) ); elseif ( isset( $_POST['checked'] ) ) $plugins = (array) $_POST['checked']; else $plugins = array(); $plugins = array_map('urldecode', $plugins); $url = 'update.php?action=update-selected&amp;plugins=' . urlencode(implode(',', $plugins)); $nonce = 'bulk-update-plugins'; wp_enqueue_script('jquery'); iframe_header(); $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); $upgrader->bulk_upgrade( $plugins ); iframe_footer(); } elseif ( 'upgrade-plugin' == $action ) { if ( ! current_user_can('update_plugins') ) wp_die(__('You do not have sufficient permissions to update plugins for this site.')); check_admin_referer('upgrade-plugin_' . $plugin); $title = __('Update Plugin'); $parent_file = 'plugins.php'; $submenu_file = 'plugins.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); $nonce = 'upgrade-plugin_' . $plugin; $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin; $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) ); $upgrader->upgrade($plugin); include(ABSPATH . 'wp-admin/admin-footer.php'); } elseif ('activate-plugin' == $action ) { if ( ! current_user_can('update_plugins') ) wp_die(__('You do not have sufficient permissions to update plugins for this site.')); check_admin_referer('activate-plugin_' . $plugin); if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) { wp_redirect( admin_url('update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) ); activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true ); wp_redirect( admin_url('update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) ); die(); } iframe_header( __('Plugin Reactivation'), true ); if ( isset($_GET['success']) ) echo '<p>' . __('Plugin reactivated successfully.') . '</p>'; if ( isset($_GET['failure']) ){ echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>'; error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR ); @ini_set('display_errors', true); //Ensure that Fatal errors are displayed. include(WP_PLUGIN_DIR . '/' . $plugin); } iframe_footer(); } elseif ( 'install-plugin' == $action ) { if ( ! current_user_can('install_plugins') ) wp_die(__('You do not have sufficient permissions to install plugins for this site.')); include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api.. check_admin_referer('install-plugin_' . $plugin); $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth. if ( is_wp_error($api) ) wp_die($api); $title = __('Plugin Install'); $parent_file = 'plugins.php'; $submenu_file = 'plugin-install.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version ); $nonce = 'install-plugin_' . $plugin; $url = 'update.php?action=install-plugin&plugin=' . $plugin; if ( isset($_GET['from']) ) $url .= '&from=' . urlencode(stripslashes($_GET['from'])); $type = 'web'; //Install plugin type, From Web or an Upload. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) ); $upgrader->install($api->download_link); include(ABSPATH . 'wp-admin/admin-footer.php'); } elseif ( 'upload-plugin' == $action ) { if ( ! current_user_can('install_plugins') ) wp_die(__('You do not have sufficient permissions to install plugins for this site.')); check_admin_referer('plugin-upload'); $file_upload = new File_Upload_Upgrader('pluginzip', 'package'); $title = __('Upload Plugin'); $parent_file = 'plugins.php'; $submenu_file = 'plugin-install.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) ); $nonce = 'plugin-upload'; $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-plugin'); $type = 'upload'; //Install plugin type, From Web or an Upload. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) ); $result = $upgrader->install( $file_upload->package ); if ( $result || is_wp_error($result) ) $file_upload->cleanup(); include(ABSPATH . 'wp-admin/admin-footer.php'); } elseif ( 'upgrade-theme' == $action ) { if ( ! current_user_can('update_themes') ) wp_die(__('You do not have sufficient permissions to update themes for this site.')); check_admin_referer('upgrade-theme_' . $theme); wp_enqueue_script( 'customize-loader' ); $title = __('Update Theme'); $parent_file = 'themes.php'; $submenu_file = 'themes.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); $nonce = 'upgrade-theme_' . $theme; $url = 'update.php?action=upgrade-theme&theme=' . $theme; $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) ); $upgrader->upgrade($theme); include(ABSPATH . 'wp-admin/admin-footer.php'); } elseif ( 'update-selected-themes' == $action ) { if ( ! current_user_can( 'update_themes' ) ) wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) ); check_admin_referer( 'bulk-update-themes' ); if ( isset( $_GET['themes'] ) ) $themes = explode( ',', stripslashes($_GET['themes']) ); elseif ( isset( $_POST['checked'] ) ) $themes = (array) $_POST['checked']; else $themes = array(); $themes = array_map('urldecode', $themes); $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes)); $nonce = 'bulk-update-themes'; wp_enqueue_script('jquery'); iframe_header(); $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); $upgrader->bulk_upgrade( $themes ); iframe_footer(); } elseif ( 'install-theme' == $action ) { if ( ! current_user_can('install_themes') ) wp_die(__('You do not have sufficient permissions to install themes for this site.')); include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api.. check_admin_referer('install-theme_' . $theme); $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth. if ( is_wp_error($api) ) wp_die($api); wp_enqueue_script( 'customize-loader' ); $title = __('Install Themes'); $parent_file = 'themes.php'; $submenu_file = 'themes.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version ); $nonce = 'install-theme_' . $theme; $url = 'update.php?action=install-theme&theme=' . $theme; $type = 'web'; //Install theme type, From Web or an Upload. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) ); $upgrader->install($api->download_link); include(ABSPATH . 'wp-admin/admin-footer.php'); } elseif ( 'upload-theme' == $action ) { if ( ! current_user_can('install_themes') ) wp_die(__('You do not have sufficient permissions to install themes for this site.')); check_admin_referer('theme-upload'); $file_upload = new File_Upload_Upgrader('themezip', 'package'); wp_enqueue_script( 'customize-loader' ); $title = __('Upload Theme'); $parent_file = 'themes.php'; $submenu_file = 'theme-install.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) ); $nonce = 'theme-upload'; $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-theme'); $type = 'upload'; //Install plugin type, From Web or an Upload. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) ); $result = $upgrader->install( $file_upload->package ); if ( $result || is_wp_error($result) ) $file_upload->cleanup(); include(ABSPATH . 'wp-admin/admin-footer.php'); } else { do_action('update-custom_' . $action); } }
01happy-blog
trunk/myblog/wp-admin/update.php
PHP
oos
9,542
<?php /** * Edit Posts Administration Screen. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! $typenow ) wp_die( __( 'Invalid post type' ) ); $post_type = $typenow; $post_type_object = get_post_type_object( $post_type ); if ( ! $post_type_object ) wp_die( __( 'Invalid post type' ) ); if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) wp_die( __( 'Cheatin&#8217; uh?' ) ); $wp_list_table = _get_list_table('WP_Posts_List_Table'); $pagenum = $wp_list_table->get_pagenum(); // Back-compat for viewing comments of an entry foreach ( array( 'p', 'attachment_id', 'page_id' ) as $_redirect ) { if ( ! empty( $_REQUEST[ $_redirect ] ) ) { wp_redirect( admin_url( 'edit-comments.php?p=' . absint( $_REQUEST[ $_redirect ] ) ) ); exit; } } unset( $_redirect ); if ( 'post' != $post_type ) { $parent_file = "edit.php?post_type=$post_type"; $submenu_file = "edit.php?post_type=$post_type"; $post_new_file = "post-new.php?post_type=$post_type"; } else { $parent_file = 'edit.php'; $submenu_file = 'edit.php'; $post_new_file = 'post-new.php'; } $doaction = $wp_list_table->current_action(); if ( $doaction ) { check_admin_referer('bulk-posts'); $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); if ( ! $sendback ) $sendback = admin_url( $parent_file ); $sendback = add_query_arg( 'paged', $pagenum, $sendback ); if ( strpos($sendback, 'post.php') !== false ) $sendback = admin_url($post_new_file); if ( 'delete_all' == $doaction ) { $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']); if ( get_post_status_object($post_status) ) // Check the post status exists first $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) ); $doaction = 'delete'; } elseif ( isset( $_REQUEST['media'] ) ) { $post_ids = $_REQUEST['media']; } elseif ( isset( $_REQUEST['ids'] ) ) { $post_ids = explode( ',', $_REQUEST['ids'] ); } elseif ( !empty( $_REQUEST['post'] ) ) { $post_ids = array_map('intval', $_REQUEST['post']); } if ( !isset( $post_ids ) ) { wp_redirect( $sendback ); exit; } switch ( $doaction ) { case 'trash': $trashed = 0; foreach( (array) $post_ids as $post_id ) { if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to move this item to the Trash.') ); if ( !wp_trash_post($post_id) ) wp_die( __('Error in moving to Trash.') ); $trashed++; } $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids) ), $sendback ); break; case 'untrash': $untrashed = 0; foreach( (array) $post_ids as $post_id ) { if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to restore this item from the Trash.') ); if ( !wp_untrash_post($post_id) ) wp_die( __('Error in restoring from Trash.') ); $untrashed++; } $sendback = add_query_arg('untrashed', $untrashed, $sendback); break; case 'delete': $deleted = 0; foreach( (array) $post_ids as $post_id ) { $post_del = & get_post($post_id); if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __('You are not allowed to delete this item.') ); if ( $post_del->post_type == 'attachment' ) { if ( ! wp_delete_attachment($post_id) ) wp_die( __('Error in deleting...') ); } else { if ( !wp_delete_post($post_id) ) wp_die( __('Error in deleting...') ); } $deleted++; } $sendback = add_query_arg('deleted', $deleted, $sendback); break; case 'edit': if ( isset($_REQUEST['bulk_edit']) ) { $done = bulk_edit_posts($_REQUEST); if ( is_array($done) ) { $done['updated'] = count( $done['updated'] ); $done['skipped'] = count( $done['skipped'] ); $done['locked'] = count( $done['locked'] ); $sendback = add_query_arg( $done, $sendback ); } } break; } $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback ); wp_redirect($sendback); exit(); } elseif ( ! empty($_REQUEST['_wp_http_referer']) ) { wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); exit; } $wp_list_table->prepare_items(); wp_enqueue_script('inline-edit-post'); $title = $post_type_object->labels->name; if ( 'post' == $post_type ) { get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This screen provides access to all of your posts. You can customize the display of this screen to suit your workflow.') . '</p>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'screen-content', 'title' => __('Screen Content'), 'content' => '<p>' . __('You can customize the display of this screen&#8217;s contents in a number of ways:') . '</p>' . '<ul>' . '<li>' . __('You can hide/display columns based on your needs and decide how many posts to list per screen using the Screen Options tab.') . '</li>' . '<li>' . __('You can filter the list of posts by post status using the text links in the upper left to show All, Published, Draft, or Trashed posts. The default view is to show all posts.') . '</li>' . '<li>' . __('You can view posts in a simple title list or with an excerpt. Choose the view you prefer by clicking on the icons at the top of the list on the right.') . '</li>' . '<li>' . __('You can refine the list to show only posts in a specific category or from a specific month by using the dropdown menus above the posts list. Click the Filter button after making your selection. You also can refine the list by clicking on the post author, category or tag in the posts list.') . '</li>' . '</ul>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'action-links', 'title' => __('Available Actions'), 'content' => '<p>' . __('Hovering over a row in the posts list will display action links that allow you to manage your post. You can perform the following actions:') . '</p>' . '<ul>' . '<li>' . __('<strong>Edit</strong> takes you to the editing screen for that post. You can also reach that screen by clicking on the post title.') . '</li>' . '<li>' . __('<strong>Quick Edit</strong> provides inline access to the metadata of your post, allowing you to update post details without leaving this screen.') . '</li>' . '<li>' . __('<strong>Trash</strong> removes your post from this list and places it in the trash, from which you can permanently delete it.') . '</li>' . '<li>' . __('<strong>Preview</strong> will show you what your draft post will look like if you publish it. View will take you to your live site to view the post. Which link is available depends on your post&#8217;s status.') . '</li>' . '</ul>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'bulk-actions', 'title' => __('Bulk Actions'), 'content' => '<p>' . __('You can also edit or move multiple posts to the trash at once. Select the posts you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.') . '</p>' . '<p>' . __('When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected posts at once. To remove a post from the grouping, just click the x next to its name in the Bulk Edit area that appears.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Posts_Screen" target="_blank">Documentation on Managing Posts</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); } elseif ( 'page' == $post_type ) { get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('Pages are similar to posts in that they have a title, body text, and associated metadata, but they are different in that they are not part of the chronological blog stream, kind of like permanent posts. Pages are not categorized or tagged, but can have a hierarchy. You can nest pages under other pages by making one the &#8220;Parent&#8221; of the other, creating a group of pages.') . '</p>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'managing-pages', 'title' => __('Managing Pages'), 'content' => '<p>' . __('Managing pages is very similar to managing posts, and the screens can be customized in the same way.') . '</p>' . '<p>' . __('You can also perform the same types of actions, including narrowing the list by using the filters, acting on a page using the action links that appear when you hover over a row, or using the Bulk Actions menu to edit the metadata for multiple pages at once.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Pages_Screen" target="_blank">Documentation on Managing Pages</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); } add_screen_option( 'per_page', array('label' => $title, 'default' => 20) ); require_once('./admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $post_type_object->labels->name ); ?> <a href="<?php echo $post_new_file ?>" class="add-new-h2"><?php echo esc_html($post_type_object->labels->add_new); ?></a> <?php if ( ! empty( $_REQUEST['s'] ) ) printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?> </h2> <?php if ( isset( $_REQUEST['locked'] ) || isset( $_REQUEST['updated'] ) || isset( $_REQUEST['deleted'] ) || isset( $_REQUEST['trashed'] ) || isset( $_REQUEST['untrashed'] ) ) { $messages = array(); ?> <div id="message" class="updated"><p> <?php if ( isset( $_REQUEST['updated'] ) && $updated = absint( $_REQUEST['updated'] ) ) { $messages[] = sprintf( _n( '%s post updated.', '%s posts updated.', $updated ), number_format_i18n( $updated ) ); } if ( isset( $_REQUEST['locked'] ) && $locked = absint( $_REQUEST['locked'] ) ) { $messages[] = sprintf( _n( '%s item not updated, somebody is editing it.', '%s items not updated, somebody is editing them.', $locked ), number_format_i18n( $locked ) ); } if ( isset( $_REQUEST['deleted'] ) && $deleted = absint( $_REQUEST['deleted'] ) ) { $messages[] = sprintf( _n( 'Item permanently deleted.', '%s items permanently deleted.', $deleted ), number_format_i18n( $deleted ) ); } if ( isset( $_REQUEST['trashed'] ) && $trashed = absint( $_REQUEST['trashed'] ) ) { $messages[] = sprintf( _n( 'Item moved to the Trash.', '%s items moved to the Trash.', $trashed ), number_format_i18n( $trashed ) ); $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0; $messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a>'; } if ( isset( $_REQUEST['untrashed'] ) && $untrashed = absint( $_REQUEST['untrashed'] ) ) { $messages[] = sprintf( _n( 'Item restored from the Trash.', '%s items restored from the Trash.', $untrashed ), number_format_i18n( $untrashed ) ); } if ( $messages ) echo join( ' ', $messages ); unset( $messages ); $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] ); ?> </p></div> <?php } ?> <?php $wp_list_table->views(); ?> <form id="posts-filter" action="" method="get"> <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?> <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_REQUEST['post_status']) ? esc_attr($_REQUEST['post_status']) : 'all'; ?>" /> <input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" /> <?php if ( ! empty( $_REQUEST['show_sticky'] ) ) { ?> <input type="hidden" name="show_sticky" value="1" /> <?php } ?> <?php $wp_list_table->display(); ?> </form> <?php if ( $wp_list_table->has_items() ) $wp_list_table->inline_edit(); ?> <div id="ajax-response"></div> <br class="clear" /> </div> <?php include('./admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/edit.php
PHP
oos
12,621
<?php /** * WordPress Administration Template Header * * @package WordPress * @subpackage Administration */ @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); if ( ! defined( 'WP_ADMIN' ) ) require_once( './admin.php' ); // In case admin-header.php is included in a function. global $title, $hook_suffix, $current_screen, $wp_locale, $pagenow, $wp_version, $current_site, $update_title, $total_update_count, $parent_file; // Catch plugins that include admin-header.php before admin.php completes. if ( empty( $current_screen ) ) set_current_screen(); get_admin_page_title(); $title = esc_html( strip_tags( $title ) ); if ( is_network_admin() ) $admin_title = __( 'Network Admin' ); elseif ( is_user_admin() ) $admin_title = __( 'Global Dashboard' ); else $admin_title = get_bloginfo( 'name' ); if ( $admin_title == $title ) $admin_title = sprintf( __( '%1$s &#8212; WordPress' ), $title ); else $admin_title = sprintf( __( '%1$s &lsaquo; %2$s &#8212; WordPress' ), $title, $admin_title ); $admin_title = apply_filters( 'admin_title', $admin_title, $title ); wp_user_settings(); _wp_admin_html_begin(); ?> <title><?php echo $admin_title; ?></title> <?php wp_enqueue_style( 'colors' ); wp_enqueue_style( 'ie' ); wp_enqueue_script('utils'); $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix); ?> <script type="text/javascript"> addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; var userSettings = { 'url': '<?php echo SITECOOKIEPATH; ?>', 'uid': '<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>', 'time':'<?php echo time() ?>' }, ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = '<?php echo $current_screen->id; ?>', typenow = '<?php echo $current_screen->post_type; ?>', adminpage = '<?php echo $admin_body_class; ?>', thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>', decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>', isRtl = <?php echo (int) is_rtl(); ?>; </script> <?php do_action('admin_enqueue_scripts', $hook_suffix); do_action("admin_print_styles-$hook_suffix"); do_action('admin_print_styles'); do_action("admin_print_scripts-$hook_suffix"); do_action('admin_print_scripts'); do_action("admin_head-$hook_suffix"); do_action('admin_head'); if ( get_user_setting('mfold') == 'f' ) $admin_body_class .= ' folded'; if ( is_admin_bar_showing() ) $admin_body_class .= ' admin-bar'; if ( is_rtl() ) $admin_body_class .= ' rtl'; $admin_body_class .= ' branch-' . str_replace( array( '.', ',' ), '-', floatval( $wp_version ) ); $admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) ); $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); if ( wp_is_mobile() ) $admin_body_class .= ' mobile'; $admin_body_class .= ' no-customize-support'; ?> </head> <body class="wp-admin no-js <?php echo apply_filters( 'admin_body_class', '' ) . " $admin_body_class"; ?>"> <script type="text/javascript"> document.body.className = document.body.className.replace('no-js','js'); </script> <?php // If the customize-loader script is enqueued, make sure the customize // body classes are correct as early as possible. if ( wp_script_is( 'customize-loader', 'queue' ) && current_user_can( 'edit_theme_options' ) ) wp_customize_support_script(); ?> <div id="wpwrap"> <?php require(ABSPATH . 'wp-admin/menu-header.php'); ?> <div id="wpcontent"> <?php do_action('in_admin_header'); ?> <div id="wpbody"> <?php unset($title_class, $blog_name, $total_update_count, $update_title); $current_screen->set_parentage( $parent_file ); ?> <div id="wpbody-content"> <?php $current_screen->render_screen_meta(); if ( is_network_admin() ) do_action('network_admin_notices'); elseif ( is_user_admin() ) do_action('user_admin_notices'); else do_action('admin_notices'); do_action('all_admin_notices'); if ( $parent_file == 'options-general.php' ) require(ABSPATH . 'wp-admin/options-head.php');
01happy-blog
trunk/myblog/wp-admin/admin-header.php
PHP
oos
4,439
<?php /** * Build Administration Menu. * * @package WordPress * @subpackage Administration */ /** * Constructs the admin menu bar. * * The elements in the array are : * 0: Menu item name * 1: Minimum level or capability required. * 2: The URL of the item's file * 3: Class * 4: ID * 5: Icon for top level menu * * @global array $menu * @name $menu * @var array */ $menu[2] = array( __('Dashboard'), 'read', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'div' ); $submenu[ 'index.php' ][0] = array( __('Home'), 'read', 'index.php' ); if ( is_multisite() ) { $submenu[ 'index.php' ][5] = array( __('My Sites'), 'read', 'my-sites.php' ); } if ( ! is_multisite() || is_super_admin() ) $update_data = wp_get_update_data(); if ( ! is_multisite() ) { $submenu[ 'index.php' ][10] = array( sprintf( __('Updates %s'), "<span class='update-plugins count-{$update_data['counts']['total']}' title='{$update_data['title']}'><span class='update-count'>" . number_format_i18n($update_data['counts']['total']) . "</span></span>" ), 'update_core', 'update-core.php'); } $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' ); $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'div' ); $submenu['edit.php'][5] = array( __('All Posts'), 'edit_posts', 'edit.php' ); /* translators: add new post */ $submenu['edit.php'][10] = array( _x('Add New', 'post'), 'edit_posts', 'post-new.php' ); $i = 15; foreach ( get_taxonomies( array(), 'objects' ) as $tax ) { if ( ! $tax->show_ui || ! in_array('post', (array) $tax->object_type, true) ) continue; $submenu['edit.php'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name ); } unset($tax); $menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'div' ); $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php'); /* translators: add new file */ $submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php'); $menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'div' ); $submenu['link-manager.php'][5] = array( _x('All Links', 'admin menu'), 'manage_links', 'link-manager.php' ); /* translators: add new links */ $submenu['link-manager.php'][10] = array( _x('Add New', 'link'), 'manage_links', 'link-add.php' ); $submenu['link-manager.php'][15] = array( __('Link Categories'), 'manage_categories', 'edit-tags.php?taxonomy=link_category' ); $menu[20] = array( __('Pages'), 'edit_pages', 'edit.php?post_type=page', '', 'menu-top menu-icon-page', 'menu-pages', 'div' ); $submenu['edit.php?post_type=page'][5] = array( __('All Pages'), 'edit_pages', 'edit.php?post_type=page' ); /* translators: add new page */ $submenu['edit.php?post_type=page'][10] = array( _x('Add New', 'page'), 'edit_pages', 'post-new.php?post_type=page' ); $i = 15; foreach ( get_taxonomies( array(), 'objects' ) as $tax ) { if ( ! $tax->show_ui || ! in_array('page', (array) $tax->object_type, true) ) continue; $submenu['edit.php?post_type=page'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&amp;post_type=page' ); } unset($tax); $awaiting_mod = wp_count_comments(); $awaiting_mod = $awaiting_mod->moderated; $menu[25] = array( sprintf( __('Comments %s'), "<span class='awaiting-mod count-$awaiting_mod'><span class='pending-count'>" . number_format_i18n($awaiting_mod) . "</span></span>" ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'div' ); unset($awaiting_mod); $submenu[ 'edit-comments.php' ][0] = array( __('All Comments'), 'edit_posts', 'edit-comments.php' ); $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group foreach ( (array) get_post_types( array('show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) as $ptype ) { $ptype_obj = get_post_type_object( $ptype ); // Check if it should be a submenu. if ( $ptype_obj->show_in_menu !== true ) continue; $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first. $ptype_for_id = sanitize_html_class( $ptype ); if ( is_string( $ptype_obj->menu_icon ) ) { $menu_icon = esc_url( $ptype_obj->menu_icon ); $ptype_class = $ptype_for_id; } else { $menu_icon = 'div'; $ptype_class = 'post'; } // if $ptype_menu_position is already populated or will be populated by a hard-coded value below, increment the position. $core_menu_positions = array(59, 60, 65, 70, 75, 80, 85, 99); while ( isset($menu[$ptype_menu_position]) || in_array($ptype_menu_position, $core_menu_positions) ) $ptype_menu_position++; $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-posts-' . $ptype_for_id, $menu_icon ); $submenu["edit.php?post_type=$ptype"][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype"); $submenu["edit.php?post_type=$ptype"][10] = array( $ptype_obj->labels->add_new, $ptype_obj->cap->edit_posts, "post-new.php?post_type=$ptype" ); $i = 15; foreach ( get_taxonomies( array(), 'objects' ) as $tax ) { if ( ! $tax->show_ui || ! in_array($ptype, (array) $tax->object_type, true) ) continue; $submenu["edit.php?post_type=$ptype"][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" ); } } unset($ptype, $ptype_obj, $ptype_class, $ptype_for_id, $ptype_menu_position, $menu_icon, $i, $tax); $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); if ( current_user_can( 'switch_themes') ) { $menu[60] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php'); if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) $submenu['themes.php'][10] = array(__('Menus'), 'edit_theme_options', 'nav-menus.php'); } else { $menu[60] = array( __('Appearance'), 'edit_theme_options', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); $submenu['themes.php'][5] = array(__('Themes'), 'edit_theme_options', 'themes.php'); if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) $submenu['themes.php'][10] = array(__('Menus'), 'edit_theme_options', 'nav-menus.php' ); } // Add 'Editor' to the bottom of the Appearance menu. if ( ! is_multisite() ) add_action('admin_menu', '_add_themes_utility_last', 101); function _add_themes_utility_last() { // Must use API on the admin_menu hook, direct modification is only possible on/before the _admin_menu hook add_submenu_page('themes.php', _x('Editor', 'theme editor'), _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php'); } $menu_perms = get_site_option( 'menu_items', array() ); if ( ! is_multisite() || is_super_admin() || ! empty( $menu_perms['plugins'] ) ) { if ( ! isset( $update_data ) ) $update_data = wp_get_update_data(); $count = ''; if ( ! is_multisite() && current_user_can( 'update_plugins' ) ) $count = "<span class='update-plugins count-{$update_data['counts']['plugins']}'><span class='plugin-count'>" . number_format_i18n($update_data['counts']['plugins']) . "</span></span>"; $menu[65] = array( sprintf( __('Plugins %s'), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' ); $submenu['plugins.php'][5] = array( __('Installed Plugins'), 'activate_plugins', 'plugins.php' ); if ( ! is_multisite() ) { /* translators: add new plugin */ $submenu['plugins.php'][10] = array( _x('Add New', 'plugin'), 'install_plugins', 'plugin-install.php' ); $submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' ); } } unset($menu_perms, $update_data); if ( current_user_can('list_users') ) $menu[70] = array( __('Users'), 'list_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' ); else $menu[70] = array( __('Profile'), 'read', 'profile.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' ); if ( current_user_can('list_users') ) { $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php. $submenu['users.php'][5] = array(__('All Users'), 'list_users', 'users.php'); if ( current_user_can('create_users') ) $submenu['users.php'][10] = array(_x('Add New', 'user'), 'create_users', 'user-new.php'); else $submenu['users.php'][10] = array(_x('Add New', 'user'), 'promote_users', 'user-new.php'); $submenu['users.php'][15] = array(__('Your Profile'), 'read', 'profile.php'); } else { $_wp_real_parent_file['users.php'] = 'profile.php'; $submenu['profile.php'][5] = array(__('Your Profile'), 'read', 'profile.php'); if ( current_user_can('create_users') ) $submenu['profile.php'][10] = array(__('Add New User'), 'create_users', 'user-new.php'); else $submenu['profile.php'][10] = array(__('Add New User'), 'promote_users', 'user-new.php'); } $menu[75] = array( __('Tools'), 'edit_posts', 'tools.php', '', 'menu-top menu-icon-tools', 'menu-tools', 'div' ); $submenu['tools.php'][5] = array( __('Available Tools'), 'edit_posts', 'tools.php' ); $submenu['tools.php'][10] = array( __('Import'), 'import', 'import.php' ); $submenu['tools.php'][15] = array( __('Export'), 'export', 'export.php' ); if ( is_multisite() && !is_main_site() ) $submenu['tools.php'][25] = array( __('Delete Site'), 'manage_options', 'ms-delete-site.php' ); if ( ! is_multisite() && defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE ) $submenu['tools.php'][50] = array(__('Network Setup'), 'manage_options', 'network.php'); $menu[80] = array( __('Settings'), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'div' ); $submenu['options-general.php'][10] = array(_x('General', 'settings screen'), 'manage_options', 'options-general.php'); $submenu['options-general.php'][15] = array(__('Writing'), 'manage_options', 'options-writing.php'); $submenu['options-general.php'][20] = array(__('Reading'), 'manage_options', 'options-reading.php'); $submenu['options-general.php'][25] = array(__('Discussion'), 'manage_options', 'options-discussion.php'); $submenu['options-general.php'][30] = array(__('Media'), 'manage_options', 'options-media.php'); $submenu['options-general.php'][35] = array(__('Privacy'), 'manage_options', 'options-privacy.php'); $submenu['options-general.php'][40] = array(__('Permalinks'), 'manage_options', 'options-permalink.php'); $_wp_last_utility_menu = 80; // The index of the last top-level menu in the utility menu group $menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator' ); // Back-compat for old top-levels $_wp_real_parent_file['post.php'] = 'edit.php'; $_wp_real_parent_file['post-new.php'] = 'edit.php'; $_wp_real_parent_file['edit-pages.php'] = 'edit.php?post_type=page'; $_wp_real_parent_file['page-new.php'] = 'edit.php?post_type=page'; $_wp_real_parent_file['wpmu-admin.php'] = 'tools.php'; $_wp_real_parent_file['ms-admin.php'] = 'tools.php'; // ensure we're backwards compatible $compat = array( 'index' => 'dashboard', 'edit' => 'posts', 'post' => 'posts', 'upload' => 'media', 'link-manager' => 'links', 'edit-pages' => 'pages', 'page' => 'pages', 'edit-comments' => 'comments', 'options-general' => 'settings', 'themes' => 'appearance', ); require_once(ABSPATH . 'wp-admin/includes/menu.php');
01happy-blog
trunk/myblog/wp-admin/menu.php
PHP
oos
12,018
<?php /** * Import WordPress Administration Screen * * @package WordPress * @subpackage Administration */ define('WP_LOAD_IMPORTERS', true); /** Load WordPress Bootstrap */ require_once ('admin.php'); if ( !current_user_can('import') ) wp_die(__('You do not have sufficient permissions to import content in this site.')); $title = __('Import'); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This screen lists links to plugins to import data from blogging/content management platforms. Choose the platform you want to import from, and click Install Now when you are prompted in the popup window. If your platform is not listed, click the link to search the plugin directory for other importer plugins to see if there is one for your platform.') . '</p>' . '<p>' . __('In previous versions of WordPress, all importers were built-in. They have been turned into plugins since most people only use them once or infrequently.') . '</p>', ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Tools_Import_Screen" target="_blank">Documentation on Import</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); $popular_importers = array(); if ( current_user_can('install_plugins') ) $popular_importers = array( 'blogger' => array( __('Blogger'), __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'), 'install' ), 'wpcat2tag' => array(__('Categories and Tags Converter'), __('Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.'), 'install', 'wp-cat2tag' ), 'livejournal' => array( __( 'LiveJournal' ), __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ), 'install' ), 'movabletype' => array( __('Movable Type and TypePad'), __('Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.'), 'install', 'mt' ), 'opml' => array( __('Blogroll'), __('Install the blogroll importer to import links in OPML format.'), 'install' ), 'rss' => array( __('RSS'), __('Install the RSS importer to import posts from an RSS feed.'), 'install' ), 'tumblr' => array( __('Tumblr'), __('Install the Tumblr importer to import posts &amp; media from Tumblr using their API.'), 'install' ), 'wordpress' => array( 'WordPress', __('Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), 'install' ) ); if ( ! empty( $_GET['invalid'] ) && !empty($popular_importers[$_GET['invalid']][3]) ) { wp_redirect( admin_url('import.php?import=' . $popular_importers[$_GET['invalid']][3]) ); exit; } add_thickbox(); wp_enqueue_script( 'plugin-install' ); require_once ('admin-header.php'); $parent_file = 'tools.php'; ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <?php if ( ! empty( $_GET['invalid'] ) ) : ?> <div class="error"><p><strong><?php _e('ERROR:')?></strong> <?php printf( __('The <strong>%s</strong> importer is invalid or is not installed.'), esc_html( $_GET['invalid'] ) ); ?></p></div> <?php endif; ?> <p><?php _e('If you have posts or comments in another system, WordPress can import those into this site. To get started, choose a system to import from below:'); ?></p> <?php $importers = get_importers(); // If a popular importer is not registered, create a dummy registration that links to the plugin installer. foreach ( $popular_importers as $pop_importer => $pop_data ) { if ( isset( $importers[$pop_importer] ) ) continue; if ( isset( $pop_data[3] ) && isset( $importers[ $pop_data[3] ] ) ) continue; $importers[$pop_importer] = $popular_importers[$pop_importer]; } if ( empty($importers) ) { echo '<p>'.__('No importers are available.').'</p>'; // TODO: make more helpful } else { uasort($importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);')); ?> <table class="widefat importers" cellspacing="0"> <?php $style = ''; foreach ($importers as $id => $data) { $style = ('class="alternate"' == $style || 'class="alternate active"' == $style) ? '' : 'alternate'; $action = ''; if ( 'install' == $data[2] ) { $plugin_slug = $id . '-importer'; if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) { // Looks like Importer is installed, But not active $plugins = get_plugins( '/' . $plugin_slug ); if ( !empty($plugins) ) { $keys = array_keys($plugins); $plugin_file = $plugin_slug . '/' . $keys[0]; $action = '<a href="' . esc_url(wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $plugin_file . '&from=import'), 'activate-plugin_' . $plugin_file)) . '"title="' . esc_attr__('Activate importer') . '"">' . $data[0] . '</a>'; } } if ( empty($action) ) { if ( is_main_site() ) { $action = '<a href="' . esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug . '&from=import&TB_iframe=true&width=600&height=550' ) ) . '" class="thickbox" title="' . esc_attr__('Install importer') . '">' . $data[0] . '</a>'; } else { $action = $data[0]; $data[1] = sprintf( __( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ), get_admin_url( $current_site->blog_id, 'import.php' ) ); } } } else { $action = "<a href='" . esc_url("admin.php?import=$id") . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>"; } if ($style != '') $style = 'class="'.$style.'"'; echo " <tr $style> <td class='import-system row-title'>$action</td> <td class='desc'>{$data[1]}</td> </tr>"; } ?> </table> <?php } if ( current_user_can('install_plugins') ) echo '<p>' . sprintf( __('If the importer you need is not listed, <a href="%s">search the plugin directory</a> to see if an importer is available.'), esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) ) . '</p>'; ?> </div> <?php include ('admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/import.php
PHP
oos
6,276
<?php /** * Multisite network settings administration panel. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ require_once( './admin.php' ); wp_redirect( network_admin_url('settings.php') );
01happy-blog
trunk/myblog/wp-admin/ms-options.php
PHP
oos
214
<?php /** * Multisite users administration panel. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ require_once( './admin.php' ); wp_redirect( network_admin_url('users.php') ); exit;
01happy-blog
trunk/myblog/wp-admin/ms-users.php
PHP
oos
207
<?php /** * Edit Comments Administration Screen. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); if ( !current_user_can('edit_posts') ) wp_die(__('Cheatin&#8217; uh?')); $wp_list_table = _get_list_table('WP_Comments_List_Table'); $pagenum = $wp_list_table->get_pagenum(); $doaction = $wp_list_table->current_action(); if ( $doaction ) { check_admin_referer( 'bulk-comments' ); if ( 'delete_all' == $doaction && !empty( $_REQUEST['pagegen_timestamp'] ) ) { $comment_status = $wpdb->escape( $_REQUEST['comment_status'] ); $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] ); $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" ); $doaction = 'delete'; } elseif ( isset( $_REQUEST['delete_comments'] ) ) { $comment_ids = $_REQUEST['delete_comments']; $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2']; } elseif ( isset( $_REQUEST['ids'] ) ) { $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) ); } elseif ( wp_get_referer() ) { wp_safe_redirect( wp_get_referer() ); exit; } $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0; $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() ); $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to ); foreach ( $comment_ids as $comment_id ) { // Check the permissions on each if ( !current_user_can( 'edit_comment', $comment_id ) ) continue; switch ( $doaction ) { case 'approve' : wp_set_comment_status( $comment_id, 'approve' ); $approved++; break; case 'unapprove' : wp_set_comment_status( $comment_id, 'hold' ); $unapproved++; break; case 'spam' : wp_spam_comment( $comment_id ); $spammed++; break; case 'unspam' : wp_unspam_comment( $comment_id ); $unspammed++; break; case 'trash' : wp_trash_comment( $comment_id ); $trashed++; break; case 'untrash' : wp_untrash_comment( $comment_id ); $untrashed++; break; case 'delete' : wp_delete_comment( $comment_id ); $deleted++; break; } } if ( $approved ) $redirect_to = add_query_arg( 'approved', $approved, $redirect_to ); if ( $unapproved ) $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to ); if ( $spammed ) $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to ); if ( $unspammed ) $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to ); if ( $trashed ) $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to ); if ( $untrashed ) $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to ); if ( $deleted ) $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to ); if ( $trashed || $spammed ) $redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to ); wp_safe_redirect( $redirect_to ); exit; } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) ); exit; } $wp_list_table->prepare_items(); wp_enqueue_script('admin-comments'); enqueue_comment_hotkeys_js(); if ( $post_id ) $title = sprintf(__('Comments on &#8220;%s&#8221;'), wp_html_excerpt(_draft_or_post_title($post_id), 50)); else $title = __('Comments'); add_screen_option( 'per_page', array('label' => _x( 'Comments', 'comments per page (screen options)' )) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __( 'You can manage comments made on your site similar to the way you manage posts and other content. This screen is customizable in the same ways as other management screens, and you can act on comments using the on-hover action links or the Bulk Actions.' ) . '</p>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'moderating-comments', 'title' => __('Moderating Comments'), 'content' => '<p>' . __( 'A yellow row means the comment is waiting for you to moderate it.' ) . '</p>' . '<p>' . __( 'In the <strong>Author</strong> column, in addition to the author&#8217;s name, email address, and blog URL, the commenter&#8217;s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' . '<p>' . __( 'In the <strong>Comment</strong> column, above each comment it says &#8220;Submitted on,&#8221; followed by the date and time the comment was left on your site. Clicking on the date/time link will take you to that comment on your live site. Hovering over any comment gives you options to approve, reply (and approve), quick edit, edit, spam mark, or trash that comment.' ) . '</p>' . '<p>' . __( 'In the <strong>In Response To</strong> column, there are three elements. The text is the name of the post that inspired the comment, and links to the post editor for that entry. The View Post link leads to that post on your live site. The small bubble with the number in it shows how many comments that post has received. If the bubble is gray, you have moderated all comments for that post. If it is blue, there are pending comments. Clicking the bubble will filter the comments screen to show only comments on that post.' ) . '</p>' . '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . '<p>' . __( '<a href="http://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' . '<p>' . __( '<a href="http://codex.wordpress.org/Comment_Spam" target="_blank">Documentation on Comment Spam</a>' ) . '</p>' . '<p>' . __( '<a href="http://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">Documentation on Keyboard Shortcuts</a>' ) . '</p>' . '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' ); require_once('./admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php if ( $post_id ) echo sprintf(__('Comments on &#8220;%s&#8221;'), sprintf('<a href="%s">%s</a>', get_edit_post_link($post_id), wp_html_excerpt(_draft_or_post_title($post_id), 50) ) ); else echo __('Comments'); if ( isset($_REQUEST['s']) && $_REQUEST['s'] ) printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( stripslashes( $_REQUEST['s'] ) ), 50 ) ) . '</span>' ); ?> </h2> <?php if ( isset( $_REQUEST['error'] ) ) { $error = (int) $_REQUEST['error']; $error_msg = ''; switch ( $error ) { case 1 : $error_msg = __( 'Oops, no comment with this ID.' ); break; case 2 : $error_msg = __( 'You are not allowed to edit comments on this post.' ); break; } if ( $error_msg ) echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>'; } if ( isset($_REQUEST['approved']) || isset($_REQUEST['deleted']) || isset($_REQUEST['trashed']) || isset($_REQUEST['untrashed']) || isset($_REQUEST['spammed']) || isset($_REQUEST['unspammed']) || isset($_REQUEST['same']) ) { $approved = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0; $deleted = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0; $trashed = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0; $untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0; $spammed = isset( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0; $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0; $same = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0; if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) { if ( $approved > 0 ) $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved ); if ( $spammed > 0 ) { $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0; $messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />'; } if ( $unspammed > 0 ) $messages[] = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed ); if ( $trashed > 0 ) { $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0; $messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />'; } if ( $untrashed > 0 ) $messages[] = sprintf( _n( '%s comment restored from the Trash', '%s comments restored from the Trash', $untrashed ), $untrashed ); if ( $deleted > 0 ) $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted ); if ( $same > 0 && $comment = get_comment( $same ) ) { switch ( $comment->comment_approved ) { case '1' : $messages[] = __('This comment is already approved.') . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; break; case 'trash' : $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>'; break; case 'spam' : $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; break; } } echo '<div id="moderated" class="updated"><p>' . implode( "<br/>\n", $messages ) . '</p></div>'; } } ?> <?php $wp_list_table->views(); ?> <form id="comments-form" action="" method="get"> <?php $wp_list_table->search_box( __( 'Search Comments' ), 'comment' ); ?> <?php if ( $post_id ) : ?> <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" /> <?php endif; ?> <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" /> <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" /> <input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('total_items') ); ?>" /> <input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('per_page') ); ?>" /> <input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('page') ); ?>" /> <?php if ( isset($_REQUEST['paged']) ) { ?> <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" /> <?php } ?> <?php $wp_list_table->display(); ?> </form> </div> <div id="ajax-response"></div> <?php wp_comment_reply('-1', true, 'detail'); wp_comment_trashnotice(); include('./admin-footer.php'); ?>
01happy-blog
trunk/myblog/wp-admin/edit-comments.php
PHP
oos
11,539
<?php /** * Your Rights administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once( './admin.php' ); $title = __( 'Freedoms' ); list( $display_version ) = explode( '-', $wp_version ); include( ABSPATH . 'wp-admin/admin-header.php' ); ?> <div class="wrap about-wrap"> <h1><?php printf( __( 'Welcome to WordPress %s' ), $display_version ); ?></h1> <div class="about-text"><?php printf( __( 'Thank you for updating to the latest version! WordPress %s is already making your website better, faster, and more attractive, just like you!' ), $display_version ); ?></div> <div class="wp-badge"><?php printf( __( 'Version %s' ), $display_version ); ?></div> <h2 class="nav-tab-wrapper"> <a href="about.php" class="nav-tab"> <?php _e( 'What&#8217;s New' ); ?> </a><a href="credits.php" class="nav-tab"> <?php _e( 'Credits' ); ?> </a><a href="freedoms.php" class="nav-tab nav-tab-active"> <?php _e( 'Freedoms' ); ?> </a> </h2> <p class="about-description"><?php printf( __( 'WordPress is Free and open source software, built by a distributed community of mostly volunteer developers from around the world. WordPress comes with some awesome, worldview-changing rights courtesy of its <a href="%s">license</a>, the GPL.' ), 'http://wordpress.org/about/license/' ); ?></p> <ol start="0"> <li><p><?php _e( 'You have the freedom to run the program, for any purpose.' ); ?></p></li> <li><p><?php _e( 'You have access to the source code, the freedom to study how the program works, and the freedom to change it to make it do what you wish.' ); ?></p></li> <li><p><?php _e( 'You have the freedom to redistribute copies of the original program so you can help your neighbor.' ); ?></p></li> <li><p><?php _e( 'You have the freedom to distribute copies of your modified versions to others. By doing this you can give the whole community a chance to benefit from your changes.' ); ?></p></li> </ol> <p><?php printf( __( 'WordPress grows when people like you tell their friends about it, and the thousands of businesses and services that are built on and around WordPress share that fact with their users. We&#8217;re flattered every time someone spreads the good word, just make sure to <a href="%s">check out our trademark guidelines</a> first.' ), 'http://wordpressfoundation.org/trademark-policy/' ); ?></p> <p><?php $plugins_url = current_user_can( 'activate_plugins' ) ? admin_url( 'plugins.php' ) : 'http://wordpress.org/extend/plugins/'; $themes_url = current_user_can( 'switch_themes' ) ? admin_url( 'themes.php' ) : 'http://wordpress.org/extend/themes/'; printf( __( 'Every plugin and theme in WordPress.org&#8217;s directory is 100%% GPL or a similarly free and compatible license, so you can feel safe finding <a href="%1$s">plugins</a> and <a href="%2$s">themes</a> there. If you get a plugin or theme from another source, make sure to <a href="%3$s">ask them if it&#8217;s GPL</a> first. If they don&#8217;t respect the WordPress license, we don&#8217;t recommend them.' ), $plugins_url, $themes_url, 'http://wordpress.org/about/license/' ); ?></p> <p><?php _e( 'Don&#8217;t you wish all software came with these freedoms? So do we! For more information, check out the <a href="http://www.fsf.org/">Free Software Foundation</a>.' ); ?></p> </div> <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>
01happy-blog
trunk/myblog/wp-admin/freedoms.php
PHP
oos
3,404
<?php /** * Accepts file uploads from swfupload or other asynchronous upload methods. * * @package WordPress * @subpackage Administration */ define('WP_ADMIN', true); if ( defined('ABSPATH') ) require_once(ABSPATH . 'wp-load.php'); else require_once('../wp-load.php'); // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead if ( is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) ) $_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie']; elseif ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) ) $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie']; if ( empty($_COOKIE[LOGGED_IN_COOKIE]) && !empty($_REQUEST['logged_in_cookie']) ) $_COOKIE[LOGGED_IN_COOKIE] = $_REQUEST['logged_in_cookie']; unset($current_user); require_once('./admin.php'); header('Content-Type: text/html; charset=' . get_option('blog_charset')); if ( !current_user_can('upload_files') ) wp_die(__('You do not have permission to upload files.')); // just fetch the detail form for that attachment if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) { $post = get_post( $id ); if ( 'attachment' != $post->post_type ) wp_die( __( 'Unknown post type.' ) ); $post_type_object = get_post_type_object( 'attachment' ); if ( ! current_user_can( $post_type_object->cap->edit_post, $id ) ) wp_die( __( 'You are not allowed to edit this item.' ) ); if ( 2 == $_REQUEST['fetch'] ) { add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2); echo get_media_item($id, array( 'send' => false, 'delete' => true )); } else { add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); echo get_media_item($id); } exit; } check_admin_referer('media-form'); $id = media_handle_upload('async-upload', $_REQUEST['post_id']); if ( is_wp_error($id) ) { echo '<div class="error-div"> <a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __('Dismiss') . '</a> <strong>' . sprintf(__('&#8220;%s&#8221; has failed to upload due to an error'), esc_html($_FILES['async-upload']['name']) ) . '</strong><br />' . esc_html($id->get_error_message()) . '</div>'; exit; } if ( $_REQUEST['short'] ) { // short form response - attachment ID only echo $id; } else { // long form response - big chunk o html $type = $_REQUEST['type']; echo apply_filters("async_upload_{$type}", $id); }
01happy-blog
trunk/myblog/wp-admin/async-upload.php
PHP
oos
2,572
<?php /** * Edit comment form for inclusion in another file. * * @package WordPress * @subpackage Administration */ // don't load directly if ( !defined('ABSPATH') ) die('-1'); ?> <form name="post" action="comment.php" method="post" id="post"> <?php wp_nonce_field('update-comment_' . $comment->comment_ID) ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php _e('Edit Comment'); ?></h2> <div id="poststuff"> <input type="hidden" name="user_ID" value="<?php echo (int) $user_ID; ?>" /> <input type="hidden" name="action" value="editedcomment" /> <input type="hidden" name="comment_ID" value="<?php echo esc_attr( $comment->comment_ID ); ?>" /> <input type="hidden" name="comment_post_ID" value="<?php echo esc_attr( $comment->comment_post_ID ); ?>" /> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <div id="namediv" class="stuffbox"> <h3><label for="name"><?php _e( 'Author' ) ?></label></h3> <div class="inside"> <table class="form-table editcomment"> <tbody> <tr valign="top"> <td class="first"><?php _e( 'Name:' ); ?></td> <td><input type="text" name="newcomment_author" size="30" value="<?php echo esc_attr( $comment->comment_author ); ?>" tabindex="1" id="name" /></td> </tr> <tr valign="top"> <td class="first"> <?php if ( $comment->comment_author_email ) { printf( __( 'E-mail (%s):' ), get_comment_author_email_link( __( 'send e-mail' ), '', '' ) ); } else { _e( 'E-mail:' ); } ?></td> <td><input type="text" name="newcomment_author_email" size="30" value="<?php echo $comment->comment_author_email; ?>" tabindex="2" id="email" /></td> </tr> <tr valign="top"> <td class="first"> <?php if ( ! empty( $comment->comment_author_url ) && 'http://' != $comment->comment_author_url ) { $link = '<a href="' . $comment->comment_author_url . '" rel="external nofollow" target="_blank">' . __('visit site') . '</a>'; printf( __( 'URL (%s):' ), apply_filters('get_comment_author_link', $link ) ); } else { _e( 'URL:' ); } ?></td> <td><input type="text" id="newcomment_author_url" name="newcomment_author_url" size="30" class="code" value="<?php echo esc_attr($comment->comment_author_url); ?>" tabindex="3" /></td> </tr> </tbody> </table> <br /> </div> </div> <div id="postdiv" class="postarea"> <?php $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' ); wp_editor( $comment->comment_content, 'content', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) ); wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> </div> </div><!-- /post-body-content --> <div id="postbox-container-1" class="postbox-container"> <div id="submitdiv" class="stuffbox" > <h3><span class='hndle'><?php _e('Status') ?></span></h3> <div class="inside"> <div class="submitbox" id="submitcomment"> <div id="minor-publishing"> <div id="minor-publishing-actions"> <div id="preview-action"> <a class="preview button" href="<?php echo get_comment_link(); ?>" target="_blank"><?php _e('View Comment'); ?></a> </div> <div class="clear"></div> </div> <div id="misc-publishing-actions"> <div class="misc-pub-section" id="comment-status-radio"> <label class="approved"><input type="radio"<?php checked( $comment->comment_approved, '1' ); ?> name="comment_status" value="1" /><?php /* translators: comment type radio button */ _ex('Approved', 'adjective') ?></label><br /> <label class="waiting"><input type="radio"<?php checked( $comment->comment_approved, '0' ); ?> name="comment_status" value="0" /><?php /* translators: comment type radio button */ _ex('Pending', 'adjective') ?></label><br /> <label class="spam"><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php /* translators: comment type radio button */ _ex('Spam', 'adjective'); ?></label> </div> <div class="misc-pub-section curtime"> <?php // translators: Publish box date format, see http://php.net/date $datef = __( 'M j, Y @ G:i' ); $stamp = __('Submitted on: <b>%1$s</b>'); $date = date_i18n( $datef, strtotime( $comment->comment_date ) ); ?> <span id="timestamp"><?php printf($stamp, $date); ?></span>&nbsp;<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a> <div id='timestampdiv' class='hide-if-js'><?php touch_time(('editcomment' == $action), 0, 5); ?></div> </div> </div> <!-- misc actions --> <div class="clear"></div> </div> <div id="major-publishing-actions"> <div id="delete-action"> <?php echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=" . ( !EMPTY_TRASH_DAYS ? 'deletecomment' : 'trashcomment' ) . "&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "'>" . ( !EMPTY_TRASH_DAYS ? __('Delete Permanently') : __('Move to Trash') ) . "</a>\n"; ?> </div> <div id="publishing-action"> <?php submit_button( __( 'Update' ), 'primary', 'save', false, array( 'tabindex' => '4' ) ); ?> </div> <div class="clear"></div> </div> </div> </div> </div><!-- /submitdiv --> </div> <div id="postbox-container-2" class="postbox-container"> <?php do_action('add_meta_boxes', 'comment', $comment); do_action('add_meta_boxes_comment', $comment); do_meta_boxes(null, 'normal', $comment); ?> </div> <input type="hidden" name="c" value="<?php echo esc_attr($comment->comment_ID) ?>" /> <input type="hidden" name="p" value="<?php echo esc_attr($comment->comment_post_ID) ?>" /> <input name="referredby" type="hidden" id="referredby" value="<?php echo esc_url(stripslashes(wp_get_referer())); ?>" /> <?php wp_original_referer_field(true, 'previous'); ?> <input type="hidden" name="noredir" value="1" /> </div><!-- /post-body --> </div> </div> </form> <script type="text/javascript"> try{document.post.name.focus();}catch(e){} </script>
01happy-blog
trunk/myblog/wp-admin/edit-form-comment.php
PHP
oos
5,888
<?php /** * Edit user administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); wp_reset_vars(array('action', 'redirect', 'profile', 'user_id', 'wp_http_referer')); $user_id = (int) $user_id; $current_user = wp_get_current_user(); if ( ! defined( 'IS_PROFILE_PAGE' ) ) define( 'IS_PROFILE_PAGE', ( $user_id == $current_user->ID ) ); if ( ! $user_id && IS_PROFILE_PAGE ) $user_id = $current_user->ID; elseif ( ! $user_id && ! IS_PROFILE_PAGE ) wp_die(__( 'Invalid user ID.' ) ); elseif ( ! get_userdata( $user_id ) ) wp_die( __('Invalid user ID.') ); wp_enqueue_script('user-profile'); $title = IS_PROFILE_PAGE ? __('Profile') : __('Edit User'); if ( current_user_can('edit_users') && !IS_PROFILE_PAGE ) $submenu_file = 'users.php'; else $submenu_file = 'profile.php'; if ( current_user_can('edit_users') && !is_user_admin() ) $parent_file = 'users.php'; else $parent_file = 'profile.php'; $profile_help = '<p>' . __('Your profile contains information about you (your &#8220;account&#8221;) as well as some personal options related to using WordPress.') . '</p>' . '<p>' . __('You can change your password, turn on keyboard shortcuts, change the color scheme of your WordPress administration screens, and turn off the WYSIWYG (Visual) editor, among other things. You can hide the Toolbar (formerly called the Admin Bar) from the front end of your site, however it cannot be disabled on the admin screens.') . '</p>' . '<p>' . __('Your username cannot be changed, but you can use other fields to enter your real name or a nickname, and change which name to display on your posts.') . '</p>' . '<p>' . __('Required fields are indicated; the rest are optional. Profile information will only be displayed if your theme is set up to do so.') . '</p>' . '<p>' . __('Remember to click the Update Profile button when you are finished.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => $profile_help, ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Users_Your_Profile_Screen" target="_blank">Documentation on User Profiles</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); $wp_http_referer = remove_query_arg(array('update', 'delete_count'), stripslashes($wp_http_referer)); $user_can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); /** * Optional SSL preference that can be turned on by hooking to the 'personal_options' action. * * @since 2.7.0 * * @param object $user User data object */ function use_ssl_preference($user) { ?> <tr> <th scope="row"><?php _e('Use https')?></th> <td><label for="use_ssl"><input name="use_ssl" type="checkbox" id="use_ssl" value="1" <?php checked('1', $user->use_ssl); ?> /> <?php _e('Always use https when visiting the admin'); ?></label></td> </tr> <?php } // Only allow super admins on multisite to edit every user. if ( is_multisite() && ! current_user_can( 'manage_network_users' ) && $user_id != $current_user->ID && ! apply_filters( 'enable_edit_any_user_configuration', true ) ) wp_die( __( 'You do not have permission to edit this user.' ) ); // Execute confirmed email change. See send_confirmation_on_profile_email(). if ( is_multisite() && IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $current_user->ID ) { $new_email = get_option( $current_user->ID . '_new_email' ); if ( $new_email[ 'hash' ] == $_GET[ 'newuseremail' ] ) { $user->ID = $current_user->ID; $user->user_email = esc_html( trim( $new_email[ 'newemail' ] ) ); if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) ); wp_update_user( get_object_vars( $user ) ); delete_option( $current_user->ID . '_new_email' ); wp_redirect( add_query_arg( array('updated' => 'true'), self_admin_url( 'profile.php' ) ) ); die(); } } elseif ( is_multisite() && IS_PROFILE_PAGE && !empty( $_GET['dismiss'] ) && $current_user->ID . '_new_email' == $_GET['dismiss'] ) { delete_option( $current_user->ID . '_new_email' ); wp_redirect( add_query_arg( array('updated' => 'true'), self_admin_url( 'profile.php' ) ) ); die(); } switch ($action) { case 'update': check_admin_referer('update-user_' . $user_id); if ( !current_user_can('edit_user', $user_id) ) wp_die(__('You do not have permission to edit this user.')); if ( IS_PROFILE_PAGE ) do_action('personal_options_update', $user_id); else do_action('edit_user_profile_update', $user_id); if ( !is_multisite() ) { $errors = edit_user($user_id); } else { $user = get_userdata( $user_id ); // Update the email address in signups, if present. if ( $user->user_login && isset( $_POST[ 'email' ] ) && is_email( $_POST[ 'email' ] ) && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_login ) ) ) $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST[ 'email' ], $user_login ) ); // WPMU must delete the user from the current blog if WP added him after editing. $delete_role = false; $blog_prefix = $wpdb->get_blog_prefix(); if ( $user_id != $current_user->ID ) { $cap = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '{$user_id}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" ); if ( !is_network_admin() && null == $cap && $_POST[ 'role' ] == '' ) { $_POST[ 'role' ] = 'contributor'; $delete_role = true; } } if ( !isset( $errors ) || ( isset( $errors ) && is_object( $errors ) && false == $errors->get_error_codes() ) ) $errors = edit_user($user_id); if ( $delete_role ) // stops users being added to current blog when they are edited delete_user_meta( $user_id, $blog_prefix . 'capabilities' ); if ( is_multisite() && is_network_admin() && !IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && !isset($super_admins) && empty( $_POST['super_admin'] ) == is_super_admin( $user_id ) ) empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id ); } if ( !is_wp_error( $errors ) ) { $redirect = (IS_PROFILE_PAGE ? "profile.php?" : "user-edit.php?user_id=$user_id&"). "updated=true"; if ( $wp_http_referer ) $redirect = add_query_arg('wp_http_referer', urlencode($wp_http_referer), $redirect); wp_redirect($redirect); exit; } default: $profileuser = get_user_to_edit($user_id); if ( !current_user_can('edit_user', $user_id) ) wp_die(__('You do not have permission to edit this user.')); include (ABSPATH . 'wp-admin/admin-header.php'); ?> <?php if ( !IS_PROFILE_PAGE && is_super_admin( $profileuser->ID ) && current_user_can( 'manage_network_options' ) ) { ?> <div class="updated"><p><strong><?php _e('Important:'); ?></strong> <?php _e('This user has super admin privileges.'); ?></p></div> <?php } ?> <?php if ( isset($_GET['updated']) ) : ?> <div id="message" class="updated"> <?php if ( IS_PROFILE_PAGE ) : ?> <p><strong><?php _e('Profile updated.') ?></strong></p> <?php else: ?> <p><strong><?php _e('User updated.') ?></strong></p> <?php endif; ?> <?php if ( $wp_http_referer && !IS_PROFILE_PAGE ) : ?> <p><a href="<?php echo esc_url( $wp_http_referer ); ?>"><?php _e('&larr; Back to Users'); ?></a></p> <?php endif; ?> </div> <?php endif; ?> <?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?> <div class="error"><p><?php echo implode( "</p>\n<p>", $errors->get_error_messages() ); ?></p></div> <?php endif; ?> <div class="wrap" id="profile-page"> <?php screen_icon(); ?> <h2> <?php echo esc_html( $title ); if ( ! IS_PROFILE_PAGE ) { if ( current_user_can( 'create_users' ) ) { ?> <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> <?php } } ?> </h2> <form id="your-profile" action="<?php echo esc_url( self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post"<?php do_action('user_edit_form_tag'); ?>> <?php wp_nonce_field('update-user_' . $user_id) ?> <?php if ( $wp_http_referer ) : ?> <input type="hidden" name="wp_http_referer" value="<?php echo esc_url($wp_http_referer); ?>" /> <?php endif; ?> <p> <input type="hidden" name="from" value="profile" /> <input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" /> </p> <h3><?php _e('Personal Options'); ?></h3> <table class="form-table"> <?php if ( rich_edit_exists() && !( IS_PROFILE_PAGE && !$user_can_edit ) ) : // don't bother showing the option if the editor has been removed ?> <tr> <th scope="row"><?php _e('Visual Editor')?></th> <td><label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="false" <?php checked('false', $profileuser->rich_editing); ?> /> <?php _e('Disable the visual editor when writing'); ?></label></td> </tr> <?php endif; ?> <?php if ( count($_wp_admin_css_colors) > 1 && has_action('admin_color_scheme_picker') ) : ?> <tr> <th scope="row"><?php _e('Admin Color Scheme')?></th> <td><?php do_action( 'admin_color_scheme_picker' ); ?></td> </tr> <?php endif; // $_wp_admin_css_colors if ( !( IS_PROFILE_PAGE && !$user_can_edit ) ) : ?> <tr> <th scope="row"><?php _e( 'Keyboard Shortcuts' ); ?></th> <td><label for="comment_shortcuts"><input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" <?php if ( !empty($profileuser->comment_shortcuts) ) checked('true', $profileuser->comment_shortcuts); ?> /> <?php _e('Enable keyboard shortcuts for comment moderation.'); ?></label> <?php _e('<a href="http://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">More information</a>'); ?></td> </tr> <?php endif; ?> <tr class="show-admin-bar"> <th scope="row"><?php _e('Toolbar')?></th> <td><fieldset><legend class="screen-reader-text"><span><?php _e('Toolbar') ?></span></legend> <label for="admin_bar_front"> <input name="admin_bar_front" type="checkbox" id="admin_bar_front" value="1"<?php checked( _get_admin_bar_pref( 'front', $profileuser->ID ) ); ?> /> <?php _e( 'Show Toolbar when viewing site' ); ?></label><br /> </fieldset> </td> </tr> <?php do_action('personal_options', $profileuser); ?> </table> <?php if ( IS_PROFILE_PAGE ) do_action('profile_personal_options', $profileuser); ?> <h3><?php _e('Name') ?></h3> <table class="form-table"> <tr> <th><label for="user_login"><?php _e('Username'); ?></label></th> <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr($profileuser->user_login); ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e('Usernames cannot be changed.'); ?></span></td> </tr> <?php if ( !IS_PROFILE_PAGE && !is_network_admin() ) : ?> <tr><th><label for="role"><?php _e('Role:') ?></label></th> <td><select name="role" id="role"> <?php // Get the highest/primary role for this user // TODO: create a function that does this: wp_get_user_role() $user_roles = $profileuser->roles; $user_role = array_shift($user_roles); // print the full list of roles with the primary one selected. wp_dropdown_roles($user_role); // print the 'no role' option. Make it selected if the user has no role yet. if ( $user_role ) echo '<option value="">' . __('&mdash; No role for this site &mdash;') . '</option>'; else echo '<option value="" selected="selected">' . __('&mdash; No role for this site &mdash;') . '</option>'; ?> </select></td></tr> <?php endif; //!IS_PROFILE_PAGE if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && !isset($super_admins) ) { ?> <tr><th><label for="role"><?php _e('Super Admin'); ?></label></th> <td> <?php if ( $profileuser->user_email != get_site_option( 'admin_email' ) ) : ?> <p><label><input type="checkbox" id="super_admin" name="super_admin"<?php checked( is_super_admin( $profileuser->ID ) ); ?> /> <?php _e( 'Grant this user super admin privileges for the Network.' ); ?></label></p> <?php else : ?> <p><?php _e( 'Super admin privileges cannot be removed because this user has the network admin email.' ); ?></p> <?php endif; ?> </td></tr> <?php } ?> <tr> <th><label for="first_name"><?php _e('First Name') ?></label></th> <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr($profileuser->first_name) ?>" class="regular-text" /></td> </tr> <tr> <th><label for="last_name"><?php _e('Last Name') ?></label></th> <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr($profileuser->last_name) ?>" class="regular-text" /></td> </tr> <tr> <th><label for="nickname"><?php _e('Nickname'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr($profileuser->nickname) ?>" class="regular-text" /></td> </tr> <tr> <th><label for="display_name"><?php _e('Display name publicly as') ?></label></th> <td> <select name="display_name" id="display_name"> <?php $public_display = array(); $public_display['display_nickname'] = $profileuser->nickname; $public_display['display_username'] = $profileuser->user_login; if ( !empty($profileuser->first_name) ) $public_display['display_firstname'] = $profileuser->first_name; if ( !empty($profileuser->last_name) ) $public_display['display_lastname'] = $profileuser->last_name; if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; } if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere $public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display; $public_display = array_map( 'trim', $public_display ); $public_display = array_unique( $public_display ); foreach ( $public_display as $id => $item ) { ?> <option <?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option> <?php } ?> </select> </td> </tr> </table> <h3><?php _e('Contact Info') ?></h3> <table class="form-table"> <tr> <th><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> <td><input type="text" name="email" id="email" value="<?php echo esc_attr($profileuser->user_email) ?>" class="regular-text" /> <?php $new_email = get_option( $current_user->ID . '_new_email' ); if ( $new_email && $new_email != $current_user->user_email ) : ?> <div class="updated inline"> <p><?php printf( __('There is a pending change of your e-mail to <code>%1$s</code>. <a href="%2$s">Cancel</a>'), $new_email['newemail'], esc_url( self_admin_url( 'profile.php?dismiss=' . $current_user->ID . '_new_email' ) ) ); ?></p> </div> <?php endif; ?> </td> </tr> <tr> <th><label for="url"><?php _e('Website') ?></label></th> <td><input type="text" name="url" id="url" value="<?php echo esc_attr($profileuser->user_url) ?>" class="regular-text code" /></td> </tr> <?php foreach (_wp_get_user_contactmethods( $profileuser ) as $name => $desc) { ?> <tr> <th><label for="<?php echo $name; ?>"><?php echo apply_filters('user_'.$name.'_label', $desc); ?></label></th> <td><input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr($profileuser->$name) ?>" class="regular-text" /></td> </tr> <?php } ?> </table> <h3><?php IS_PROFILE_PAGE ? _e('About Yourself') : _e('About the user'); ?></h3> <table class="form-table"> <tr> <th><label for="description"><?php _e('Biographical Info'); ?></label></th> <td><textarea name="description" id="description" rows="5" cols="30"><?php echo $profileuser->description; // textarea_escaped ?></textarea><br /> <span class="description"><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></span></td> </tr> <?php $show_password_fields = apply_filters('show_password_fields', true, $profileuser); if ( $show_password_fields ) : ?> <tr id="password"> <th><label for="pass1"><?php _e('New Password'); ?></label></th> <td><input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" /> <span class="description"><?php _e("If you would like to change the password type a new one. Otherwise leave this blank."); ?></span><br /> <input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" /> <span class="description"><?php _e("Type your new password again."); ?></span><br /> <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div> <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p> </td> </tr> <?php endif; ?> </table> <?php if ( IS_PROFILE_PAGE ) do_action( 'show_user_profile', $profileuser ); else do_action( 'edit_user_profile', $profileuser ); ?> <?php if ( count($profileuser->caps) > count($profileuser->roles) && apply_filters('additional_capabilities_display', true, $profileuser) ) { ?> <br class="clear" /> <table width="99%" style="border: none;" cellspacing="2" cellpadding="3" class="editform"> <tr> <th scope="row"><?php _e('Additional Capabilities') ?></th> <td><?php $output = ''; foreach ( $profileuser->caps as $cap => $value ) { if ( !$wp_roles->is_role($cap) ) { if ( $output != '' ) $output .= ', '; $output .= $value ? $cap : "Denied: {$cap}"; } } echo $output; ?></td> </tr> </table> <?php } ?> <input type="hidden" name="action" value="update" /> <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr($user_id); ?>" /> <?php submit_button( IS_PROFILE_PAGE ? __('Update Profile') : __('Update User') ); ?> </form> </div> <?php break; } ?> <script type="text/javascript" charset="utf-8"> if (window.location.hash == '#password') { document.getElementById('pass1').focus(); } </script> <?php include( ABSPATH . 'wp-admin/admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/user-edit.php
PHP
oos
18,774
<?php /** * Revisions administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); wp_enqueue_script('list-revisions'); wp_reset_vars(array('revision', 'left', 'right', 'action')); $revision_id = absint($revision); $left = absint($left); $right = absint($right); $redirect = 'edit.php'; switch ( $action ) : case 'restore' : if ( !$revision = wp_get_post_revision( $revision_id ) ) break; if ( !current_user_can( 'edit_post', $revision->post_parent ) ) break; if ( !$post = get_post( $revision->post_parent ) ) break; // Revisions disabled and we're not looking at an autosave if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) { $redirect = 'edit.php?post_type=' . $post->post_type; break; } check_admin_referer( "restore-post_$post->ID|$revision->ID" ); wp_restore_post_revision( $revision->ID ); $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); break; case 'diff' : if ( !$left_revision = get_post( $left ) ) break; if ( !$right_revision = get_post( $right ) ) break; if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) ) break; // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post if ( $left_revision->ID == $right_revision->ID ) { $redirect = get_edit_post_link( $left_revision->ID ); include( './js/revisions-js.php' ); break; } // Don't allow reverse diffs? if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) { $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) ); break; } if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left $post =& $left_revision; elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right $post =& $right_revision; elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent $post = get_post( $left_revision->post_parent ); else break; // Don't diff two unrelated revisions if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled if ( // we're not looking at an autosave ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) ) || // we're not comparing an autosave to the current post ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID ) ) { $redirect = 'edit.php?post_type=' . $post->post_type; break; } } if ( // They're the same $left_revision->ID == $right_revision->ID || // Neither is a revision ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) ) ) break; $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; $h2 = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title ); $title = __( 'Revisions' ); $left = $left_revision->ID; $right = $right_revision->ID; $redirect = false; break; case 'view' : default : if ( !$revision = wp_get_post_revision( $revision_id ) ) break; if ( !$post = get_post( $revision->post_parent ) ) break; if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) ) break; // Revisions disabled and we're not looking at an autosave if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) { $redirect = 'edit.php?post_type=' . $post->post_type; break; } $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; $revision_title = wp_post_revision_title( $revision, false ); $h2 = sprintf( __( 'Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title ); $title = __( 'Revisions' ); // Sets up the diff radio buttons $left = $revision->ID; $right = $post->ID; $redirect = false; break; endswitch; // Empty post_type means either malformed object found, or no valid parent was found. if ( !$redirect && empty($post->post_type) ) $redirect = 'edit.php'; if ( !empty($redirect) ) { wp_redirect( $redirect ); exit; } // This is so that the correct "Edit" menu item is selected. if ( !empty($post->post_type) && 'post' != $post->post_type ) $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type; else $parent_file = $submenu_file = 'edit.php'; require_once( './admin-header.php' ); ?> <div class="wrap"> <h2 class="long-header"><?php echo $h2; ?></h2> <table class="form-table ie-fixed"> <col class="th" /> <?php if ( 'diff' == $action ) : ?> <tr id="revision"> <th scope="row"></th> <th scope="col" class="th-full"> <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span> <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span> </th> </tr> <?php endif; // use get_post_to_edit filters? $identical = true; foreach ( _wp_post_revision_fields() as $field => $field_title ) : if ( 'diff' == $action ) { $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field ); $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field ); if ( !$content = wp_text_diff( $left_content, $right_content ) ) continue; // There is no difference between left and right $identical = false; } else { add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' ); $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field ); } ?> <tr id="revision-field-<?php echo $field; ?>"> <th scope="row"><?php echo esc_html( $field_title ); ?></th> <td><div class="pre"><?php echo $content; ?></div></td> </tr> <?php endforeach; if ( 'diff' == $action && $identical ) : ?> <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr> <?php endif; ?> </table> <br class="clear" /> <h3><?php echo $title; ?></h3> <?php $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ); if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) $args['type'] = 'autosave'; wp_list_post_revisions( $post, $args ); ?> </div> <?php require_once( './admin-footer.php' );
01happy-blog
trunk/myblog/wp-admin/revision.php
PHP
oos
6,667
<?php /** * WordPress Options Header. * * Resets variables: 'action', 'standalone', and 'option_group_id'. Displays * updated message, if updated variable is part of the URL query. * * @package WordPress * @subpackage Administration */ wp_reset_vars(array('action', 'standalone', 'option_group_id')); if ( isset( $_GET['updated'] ) && isset( $_GET['page'] ) ) { // For backwards compat with plugins that don't use the Settings API and just set updated=1 in the redirect add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); } settings_errors();
01happy-blog
trunk/myblog/wp-admin/options-head.php
PHP
oos
589
<?php /** * WordPress Administration Generic POST Handler. * * @package WordPress * @subpackage Administration */ /** We are located in WordPress Administration Screens */ define('WP_ADMIN', true); if ( defined('ABSPATH') ) require_once(ABSPATH . 'wp-load.php'); else require_once('../wp-load.php'); require_once(ABSPATH . 'wp-admin/includes/admin.php'); nocache_headers(); do_action('admin_init'); $action = 'admin_post'; if ( !wp_validate_auth_cookie() ) $action .= '_nopriv'; if ( !empty($_REQUEST['action']) ) $action .= '_' . $_REQUEST['action']; do_action($action);
01happy-blog
trunk/myblog/wp-admin/admin-post.php
PHP
oos
590
<?php /** * Media management action handler. * * @package WordPress * @subpackage Administration */ /** Load WordPress Administration Bootstrap */ require_once('./admin.php'); $parent_file = 'upload.php'; $submenu_file = 'upload.php'; wp_reset_vars(array('action')); switch( $action ) : case 'editattachment' : $attachment_id = (int) $_POST['attachment_id']; check_admin_referer('media-form'); if ( !current_user_can('edit_post', $attachment_id) ) wp_die ( __('You are not allowed to edit this attachment.') ); $errors = media_upload_form_handler(); if ( empty($errors) ) { $location = 'media.php'; if ( $referer = wp_get_original_referer() ) { if ( false !== strpos($referer, 'upload.php') || ( url_to_postid($referer) == $attachment_id ) ) $location = $referer; } if ( false !== strpos($location, 'upload.php') ) { $location = remove_query_arg('message', $location); $location = add_query_arg('posted', $attachment_id, $location); } elseif ( false !== strpos($location, 'media.php') ) { $location = add_query_arg('message', 'updated', $location); } wp_redirect($location); exit; } // no break case 'edit' : $title = __('Edit Media'); if ( empty($errors) ) $errors = null; if ( empty( $_GET['attachment_id'] ) ) { wp_redirect( admin_url('upload.php') ); exit(); } $att_id = (int) $_GET['attachment_id']; if ( !current_user_can('edit_post', $att_id) ) wp_die ( __('You are not allowed to edit this attachment.') ); $att = get_post($att_id); if ( empty($att->ID) ) wp_die( __('You attempted to edit an attachment that doesn&#8217;t exist. Perhaps it was deleted?') ); if ( 'attachment' !== $att->post_type ) wp_die( __('You attempted to edit an item that isn&#8217;t an attachment. Please go back and try again.') ); if ( $att->post_status == 'trash' ) wp_die( __('You can&#8217;t edit this attachment because it is in the Trash. Please move it out of the Trash and try again.') ); add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2); wp_enqueue_script( 'wp-ajax-response' ); wp_enqueue_script('image-edit'); wp_enqueue_style('imgareaselect'); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This screen allows you to edit five fields for metadata in a file within the media library.') . '</p>' . '<p>' . __('For images only, you can click on Edit Image under the thumbnail to expand out an inline image editor with icons for cropping, rotating, or flipping the image as well as for undoing and redoing. The boxes on the right give you more options for scaling the image, for cropping it, and for cropping the thumbnail in a different way than you crop the original image. You can click on Help in those boxes to get more information.') . '</p>' . '<p>' . __('Note that you crop the image by clicking on it (the Crop icon is already selected) and dragging the cropping frame to select the desired part. Then click Save to retain the cropping.') . '</p>' . '<p>' . __('Remember to click Update Media to save metadata entered or changed.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Media_Add_New_Screen#Edit_Media" target="_blank">Documentation on Edit Media</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); require( './admin-header.php' ); $parent_file = 'upload.php'; $message = ''; $class = ''; if ( isset($_GET['message']) ) { switch ( $_GET['message'] ) : case 'updated' : $message = __('Media attachment updated.'); $class = 'updated'; break; endswitch; } if ( $message ) echo "<div id='message' class='$class'><p>$message</p></div>\n"; ?> <div class="wrap"> <?php screen_icon(); ?> <h2> <?php echo esc_html( $title ); if ( current_user_can( 'upload_files' ) ) { ?> <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a> <?php } ?> </h2> <form method="post" action="" class="media-upload-form" id="media-single-form"> <p class="submit" style="padding-bottom: 0;"> <?php submit_button( __( 'Update Media' ), 'primary', 'save', false ); ?> </p> <div class="media-single"> <div id='media-item-<?php echo $att_id; ?>' class='media-item'> <?php echo get_media_item( $att_id, array( 'toggle' => false, 'send' => false, 'delete' => false, 'show_title' => false, 'errors' => !empty($errors[$att_id]) ? $errors[$att_id] : null ) ); ?> </div> </div> <?php submit_button( __( 'Update Media' ), 'primary', 'save' ); ?> <input type="hidden" name="post_id" id="post_id" value="<?php echo isset($post_id) ? esc_attr($post_id) : ''; ?>" /> <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr($att_id); ?>" /> <input type="hidden" name="action" value="editattachment" /> <?php wp_original_referer_field(true, 'previous'); ?> <?php wp_nonce_field('media-form'); ?> </form> </div> <?php require( './admin-footer.php' ); exit; default: wp_redirect( admin_url('upload.php') ); exit; endswitch;
01happy-blog
trunk/myblog/wp-admin/media.php
PHP
oos
5,207
<?php /** * Dashboard Administration Screen * * @package WordPress * @subpackage Administration */ /** Load WordPress Bootstrap */ require_once('./admin.php'); /** Load WordPress dashboard API */ require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); wp_dashboard_setup(); wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'plugin-install' ); wp_enqueue_script( 'media-upload' ); add_thickbox(); if ( wp_is_mobile() ) wp_enqueue_script( 'jquery-touch-punch' ); $title = __('Dashboard'); $parent_file = 'index.php'; if ( is_user_admin() ) add_screen_option('layout_columns', array('max' => 4, 'default' => 1) ); else add_screen_option('layout_columns', array('max' => 4, 'default' => 2) ); $help = '<p>' . __( 'Welcome to your WordPress Dashboard! This is the screen you will see when you log in to your site, and gives you access to all the site management features of WordPress. You can get help for any screen by clicking the Help tab in the upper corner.' ) . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __( 'Overview' ), 'content' => $help, ) ); // Help tabs $help = '<p>' . __('The left-hand navigation menu provides links to all of the WordPress administration screens, with submenu items displayed on hover. You can minimize this menu to a narrow icon strip by clicking on the Collapse Menu arrow at the bottom.') . '</p>'; $help .= '<p>' . __('Links in the Toolbar at the top of the screen connect your dashboard and the front end of your site, and provide access to your profile and helpful WordPress information.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'help-navigation', 'title' => __('Navigation'), 'content' => $help, ) ); $help = '<p>' . __('You can use the following controls to arrange your Dashboard screen to suit your workflow. This is true on most other administration screens as well.') . '</p>'; $help .= '<p>' . __('<strong>Screen Options</strong> - Use the Screen Options tab to choose which Dashboard boxes to show, and how many columns to display.') . '</p>'; $help .= '<p>' . __('<strong>Drag and Drop</strong> - To rearrange the boxes, drag and drop by clicking on the title bar of the selected box and releasing when you see a gray dotted-line rectangle appear in the location you want to place the box.') . '</p>'; $help .= '<p>' . __('<strong>Box Controls</strong> - Click the title bar of the box to expand or collapse it. In addition, some box have configurable content, and will show a &#8220;Configure&#8221; link in the title bar if you hover over it.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'help-layout', 'title' => __('Layout'), 'content' => $help, ) ); $help = '<p>' . __('The boxes on your Dashboard screen are:') . '</p>'; if ( current_user_can( 'edit_posts' ) ) $help .= '<p>' . __('<strong>Right Now</strong> - Displays a summary of the content on your site and identifies which theme and version of WordPress you are using.') . '</p>'; if ( current_user_can( 'moderate_comments' ) ) $help .= '<p>' . __('<strong>Recent Comments</strong> - Shows the most recent comments on your posts (configurable, up to 30) and allows you to moderate them.') . '</p>'; if ( current_user_can( 'publish_posts' ) ) $help .= '<p>' . __('<strong>Incoming Links</strong> - Shows links to your site found by Google Blog Search.') . '</p>'; if ( current_user_can( 'edit_posts' ) ) { $help .= '<p>' . __('<strong>QuickPress</strong> - Allows you to create a new post and either publish it or save it as a draft.') . '</p>'; $help .= '<p>' . __('<strong>Recent Drafts</strong> - Displays links to the 5 most recent draft posts you&#8217;ve started.') . '</p>'; } $help .= '<p>' . __('<strong>WordPress Blog</strong> - Latest news from the official WordPress project.') . '</p>'; $help .= '<p>' . __('<strong>Other WordPress News</strong> - Shows the <a href="http://planet.wordpress.org" target="_blank">WordPress Planet</a> feed. You can configure it to show a different feed of your choosing.') . '</p>'; if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) $help .= '<p>' . __('<strong>Plugins</strong> - Features the most popular, newest, and recently updated plugins from the WordPress.org Plugin Directory.') . '</p>'; if ( current_user_can( 'edit_theme_options' ) ) $help .= '<p>' . __('<strong>Welcome</strong> - Shows links for some of the most common tasks when setting up a new site.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'help-content', 'title' => __('Content'), 'content' => $help, ) ); unset( $help ); get_current_screen()->set_help_sidebar( '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . '<p>' . __( '<a href="http://codex.wordpress.org/Dashboard_Screen" target="_blank">Documentation on Dashboard</a>' ) . '</p>' . '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' ); include (ABSPATH . 'wp-admin/admin-header.php'); $today = current_time('mysql', 1); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <?php wp_welcome_panel(); ?> <div id="dashboard-widgets-wrap"> <?php wp_dashboard(); ?> <div class="clear"></div> </div><!-- dashboard-widgets-wrap --> </div><!-- wrap --> <?php require(ABSPATH . 'wp-admin/admin-footer.php'); ?>
01happy-blog
trunk/myblog/wp-admin/index.php
PHP
oos
5,391
<?php /** * Themes administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') ) wp_die( __( 'Cheatin&#8217; uh?' ) ); $wp_list_table = _get_list_table('WP_Themes_List_Table'); if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) { if ( 'activate' == $_GET['action'] ) { check_admin_referer('switch-theme_' . $_GET['stylesheet']); $theme = wp_get_theme( $_GET['stylesheet'] ); if ( ! $theme->exists() || ! $theme->is_allowed() ) wp_die( __( 'Cheatin&#8217; uh?' ) ); switch_theme( $theme->get_template(), $theme->get_stylesheet() ); wp_redirect( admin_url('themes.php?activated=true') ); exit; } elseif ( 'delete' == $_GET['action'] ) { check_admin_referer('delete-theme_' . $_GET['stylesheet']); $theme = wp_get_theme( $_GET['stylesheet'] ); if ( !current_user_can('delete_themes') || ! $theme->exists() ) wp_die( __( 'Cheatin&#8217; uh?' ) ); delete_theme($_GET['stylesheet']); wp_redirect( admin_url('themes.php?deleted=true') ); exit; } } $wp_list_table->prepare_items(); $title = __('Manage Themes'); $parent_file = 'themes.php'; if ( current_user_can( 'switch_themes' ) ) : $help_manage = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>' . '<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Live Preview link (see "Previewing and Customizing" help tab). To change themes, click the Activate link.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => $help_manage ) ); if ( current_user_can( 'install_themes' ) ) { if ( is_multisite() ) { $help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>'; } else { $help_install = '<p>' . sprintf( __('If you would like to see more themes to choose from, click on the &#8220;Install Themes&#8221; tab and you will be able to browse or search for additional themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. Themes in the WordPress.org Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!'), 'http://wordpress.org/extend/themes/' ) . '</p>'; } get_current_screen()->add_help_tab( array( 'id' => 'adding-themes', 'title' => __('Adding Themes'), 'content' => $help_install ) ); } add_thickbox(); endif; // switch_themes if ( current_user_can( 'edit_theme_options' ) ) { $help_customize = '<p>' . __('Click on the "Live Preview" link under any theme to preview that theme and change theme options in a separate, full-screen view. Any installed theme can be previewed and customized in this way.') . '</p>'. '<p>' . __('The theme being previewed is fully interactive &mdash; navigate to different pages to see how the theme handles posts, archives, and other page templates.') . '</p>' . '<p>' . __('In the left-hand pane you can edit the theme settings. The settings will differ, depending on what theme features the theme being previewed supports. To accept the new settings and activate the theme all in one step, click the "Save &amp; Activate" button at the top of the left-hand pane.') . '</p>' . '<p>' . __('When previewing on smaller monitors, you can use the "Collapse" icon at the bottom of the left-hand pane. This will hide the pane, giving you more room to preview your site in the new theme. To bring the pane back, click on the Collapse icon again.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'customize-preview-themes', 'title' => __('Previewing and Customizing'), 'content' => $help_customize ) ); } get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); wp_enqueue_script( 'theme' ); wp_enqueue_script( 'customize-loader' ); require_once('./admin-header.php'); ?> <div class="wrap"><?php screen_icon(); if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?> <h2 class="nav-tab-wrapper"> <a href="themes.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a><a href="<?php echo admin_url( 'theme-install.php'); ?>" class="nav-tab"><?php echo esc_html_x('Install Themes', 'theme'); ?></a> <?php else : ?> <h2><?php echo esc_html( $title ); ?> <?php endif; ?> </h2> <?php if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?> <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div> <?php elseif ( isset($_GET['activated']) ) : if ( isset( $_GET['previewed'] ) ) { ?> <div id="message2" class="updated"><p><?php printf( __( 'Settings saved and theme activated. <a href="%s">Visit site</a>.' ), home_url( '/' ) ); ?></p></div> <?php } elseif ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?> <div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php } else { ?> <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php } elseif ( isset($_GET['deleted']) ) : ?> <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div> <?php endif; $ct = wp_get_theme(); $screenshot = $ct->get_screenshot(); $class = $screenshot ? 'has-screenshot' : ''; $customize_title = sprintf( __( 'Customize &#8220;%s&#8221;' ), $ct->display('Name') ); ?> <div id="current-theme" class="<?php echo esc_attr( $class ); ?>"> <?php if ( $screenshot ) : ?> <?php if ( current_user_can( 'edit_theme_options' ) ) : ?> <a href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>"> <img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" /> </a> <?php endif; ?> <img class="hide-if-customize" src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" /> <?php endif; ?> <h3><?php _e('Current Theme'); ?></h3> <h4> <?php echo $ct->display('Name'); ?> </h4> <div> <ul class="theme-info"> <li><?php printf( __('By %s'), $ct->display('Author') ); ?></li> <li><?php printf( __('Version %s'), $ct->display('Version') ); ?></li> </ul> <p class="theme-description"><?php echo $ct->display('Description'); ?></p> <?php theme_update_available( $ct ); ?> </div> <?php // Pretend you didn't see this. $options = array(); if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) { foreach ( (array) $submenu['themes.php'] as $item) { $class = ''; if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] ) continue; // 0 = name, 1 = capability, 2 = file if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) ) $class = ' class="current"'; if ( !empty($submenu[$item[2]]) ) { $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index. $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]); if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook)) $options[] = "<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>"; else $options[] = "<a href='{$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>"; } else if ( current_user_can($item[1]) ) { if ( file_exists(ABSPATH . 'wp-admin/' . $item[2]) ) { $options[] = "<a href='{$item[2]}'$class>{$item[0]}</a>"; } else { $options[] = "<a href='themes.php?page={$item[2]}'$class>{$item[0]}</a>"; } } } } if ( $options || current_user_can( 'edit_theme_options' ) ) : ?> <div class="theme-options"> <?php if ( current_user_can( 'edit_theme_options' ) ) : ?> <a id="customize-current-theme-link" href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>"><?php _e( 'Customize' ); ?></a> <?php endif; // edit_theme_options if ( $options ) : ?> <span><?php _e( 'Options:' )?></span> <ul> <?php foreach ( $options as $option ) : ?> <li><?php echo $option; ?></li> <?php endforeach; ?> </ul> </div> <?php endif; // options endif; // options || edit_theme_options ?> </div> <br class="clear" /> <?php if ( ! current_user_can( 'switch_themes' ) ) { echo '</div>'; require( './admin-footer.php' ); exit; } ?> <form class="search-form filter-form" action="" method="get"> <h3 class="available-themes"><?php _e('Available Themes'); ?></h3> <?php if ( !empty( $_REQUEST['s'] ) || !empty( $_REQUEST['features'] ) || $wp_list_table->has_items() ) : ?> <p class="search-box"> <label class="screen-reader-text" for="theme-search-input"><?php _e('Search Installed Themes'); ?>:</label> <input type="search" id="theme-search-input" name="s" value="<?php _admin_search_query(); ?>" /> <?php submit_button( __( 'Search Installed Themes' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?> <a id="filter-click" href="?filter=1"><?php _e( 'Feature Filter' ); ?></a> </p> <div id="filter-box" style="<?php if ( empty($_REQUEST['filter']) ) echo 'display: none;'; ?>"> <?php $feature_list = get_theme_feature_list(); ?> <div class="feature-filter"> <p class="install-help"><?php _e('Theme filters') ?></p> <?php if ( !empty( $_REQUEST['filter'] ) ) : ?> <input type="hidden" name="filter" value="1" /> <?php endif; ?> <?php foreach ( $feature_list as $feature_name => $features ) : $feature_name = esc_html( $feature_name ); ?> <div class="feature-container"> <div class="feature-name"><?php echo $feature_name ?></div> <ol class="feature-group"> <?php foreach ( $features as $key => $feature ) : $feature_name = $feature; $feature_name = esc_html( $feature_name ); $feature = esc_attr( $feature ); ?> <li> <input type="checkbox" name="features[]" id="feature-id-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( in_array( $key, $wp_list_table->features ) ); ?>/> <label for="feature-id-<?php echo $key; ?>"><?php echo $feature_name; ?></label> </li> <?php endforeach; ?> </ol> </div> <?php endforeach; ?> <div class="feature-container"> <?php submit_button( __( 'Apply Filters' ), 'button-secondary submitter', false, false, array( 'id' => 'filter-submit' ) ); ?> &nbsp; <a id="mini-filter-click" href="<?php echo esc_url( remove_query_arg( array('filter', 'features', 'submit') ) ); ?>"><?php _e( 'Close filters' )?></a> </div> <br/> </div> <br class="clear"/> </div> <?php endif; ?> <br class="clear" /> <?php $wp_list_table->display(); ?> </form> <br class="clear" /> <?php // List broken themes, if any. if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) { ?> <h3><?php _e('Broken Themes'); ?></h3> <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p> <table id="broken-themes"> <tr> <th><?php _ex('Name', 'theme name'); ?></th> <th><?php _e('Description'); ?></th> </tr> <?php $alt = ''; foreach ( $broken_themes as $broken_theme ) { $alt = ('class="alternate"' == $alt) ? '' : 'class="alternate"'; echo " <tr $alt> <td>" . $broken_theme->get('Name') ."</td> <td>" . $broken_theme->errors()->get_error_message() . "</td> </tr>"; } ?> </table> <?php } ?> </div> <?php require('./admin-footer.php'); ?>
01happy-blog
trunk/myblog/wp-admin/themes.php
PHP
oos
12,378
<?php /** * Disable error reporting * * Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging */ error_reporting(0); /** Set ABSPATH for execution */ define( 'ABSPATH', dirname(dirname(__FILE__)) . '/' ); define( 'WPINC', 'wp-includes' ); /** * @ignore */ function __() {} /** * @ignore */ function _x() {} /** * @ignore */ function add_filter() {} /** * @ignore */ function esc_attr() {} /** * @ignore */ function apply_filters() {} /** * @ignore */ function get_option() {} /** * @ignore */ function is_lighttpd_before_150() {} /** * @ignore */ function add_action() {} /** * @ignore */ function did_action() {} /** * @ignore */ function do_action_ref_array() {} /** * @ignore */ function get_bloginfo() {} /** * @ignore */ function is_admin() {return true;} /** * @ignore */ function site_url() {} /** * @ignore */ function admin_url() {} /** * @ignore */ function home_url() {} /** * @ignore */ function includes_url() {} /** * @ignore */ function wp_guess_url() {} if ( ! function_exists( 'json_encode' ) ) : /** * @ignore */ function json_encode() {} endif; function get_file($path) { if ( function_exists('realpath') ) $path = realpath($path); if ( ! $path || ! @is_file($path) ) return ''; return @file_get_contents($path); } $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $_GET['load'] ); $load = explode(',', $load); if ( empty($load) ) exit; require(ABSPATH . WPINC . '/script-loader.php'); require(ABSPATH . WPINC . '/version.php'); $compress = ( isset($_GET['c']) && $_GET['c'] ); $force_gzip = ( $compress && 'gzip' == $_GET['c'] ); $expires_offset = 31536000; $out = ''; $wp_scripts = new WP_Scripts(); wp_default_scripts($wp_scripts); foreach( $load as $handle ) { if ( !array_key_exists($handle, $wp_scripts->registered) ) continue; $path = ABSPATH . $wp_scripts->registered[$handle]->src; $out .= get_file($path) . "\n"; } header('Content-Type: application/x-javascript; charset=UTF-8'); header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT'); header("Cache-Control: public, max-age=$expires_offset"); if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) { header('Vary: Accept-Encoding'); // Handle proxies if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { header('Content-Encoding: deflate'); $out = gzdeflate( $out, 3 ); } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) { header('Content-Encoding: gzip'); $out = gzencode( $out, 3 ); } } echo $out; exit;
01happy-blog
trunk/myblog/wp-admin/load-scripts.php
PHP
oos
2,759
<?php /** * Add Link Administration Screen. * * @package WordPress * @subpackage Administration */ /** Load WordPress Administration Bootstrap */ require_once('./admin.php'); if ( ! current_user_can('manage_links') ) wp_die(__('You do not have sufficient permissions to add links to this site.')); $title = __('Add New Link'); $parent_file = 'link-manager.php'; wp_reset_vars(array('action', 'cat_id', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]')); wp_enqueue_script('link'); wp_enqueue_script('xfn'); if ( wp_is_mobile() ) wp_enqueue_script( 'jquery-touch-punch' ); $link = get_default_link_to_edit(); include('./edit-link-form.php'); require('./admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/link-add.php
PHP
oos
811
<?php /** * WordPress Administration for Navigation Menus * Interface functions * * @version 2.0.0 * * @package WordPress * @subpackage Administration */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); // Load all the nav menu interface functions require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' ); if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) ) wp_die( __( 'Your theme does not support navigation menus or widgets.' ) ); // Permissions Check if ( ! current_user_can('edit_theme_options') ) wp_die( __( 'Cheatin&#8217; uh?' ) ); // jQuery wp_enqueue_script( 'jquery-ui-draggable' ); wp_enqueue_script( 'jquery-ui-droppable' ); wp_enqueue_script( 'jquery-ui-sortable' ); // Nav Menu functions wp_enqueue_script( 'nav-menu' ); // Metaboxes wp_enqueue_script( 'common' ); wp_enqueue_script( 'wp-lists' ); wp_enqueue_script( 'postbox' ); if ( wp_is_mobile() ) wp_enqueue_script( 'jquery-touch-punch' ); // Container for any messages displayed to the user $messages = array(); // Container that stores the name of the active menu $nav_menu_selected_title = ''; // The menu id of the current menu being edited $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0; // Allowed actions: add, update, delete $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit'; switch ( $action ) { case 'add-menu-item': check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' ); if ( isset( $_REQUEST['nav-menu-locations'] ) ) set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) ); elseif ( isset( $_REQUEST['menu-item'] ) ) wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] ); break; case 'move-down-menu-item' : // moving down a menu item is the same as moving up the next in order check_admin_referer( 'move-menu_item' ); $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0; if ( is_nav_menu_item( $menu_item_id ) ) { $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) ); if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) { $menu_id = (int) $menus[0]; $ordered_menu_items = wp_get_nav_menu_items( $menu_id ); $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) ); // set up the data we need in one pass through the array of menu items $dbids_to_orders = array(); $orders_to_dbids = array(); foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) { if ( isset( $ordered_menu_item_object->ID ) ) { if ( isset( $ordered_menu_item_object->menu_order ) ) { $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order; $orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID; } } } // get next in order if ( isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1] ) ) { $next_item_id = $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1]; $next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) ); // if not siblings of same parent, bubble menu item up but keep order if ( ! empty( $menu_item_data['menu_item_parent'] ) && ( empty( $next_item_data['menu_item_parent'] ) || $next_item_data['menu_item_parent'] != $menu_item_data['menu_item_parent'] ) ) { $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0; $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) ); if ( ! is_wp_error( $parent_object ) ) { $parent_data = (array) $parent_object; $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent']; update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); } // make menu item a child of its next sibling } else { $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1; $menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1; $menu_item_data['menu_item_parent'] = $next_item_data['ID']; update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); wp_update_post($menu_item_data); wp_update_post($next_item_data); } // the item is last but still has a parent, so bubble up } elseif ( ! empty( $menu_item_data['menu_item_parent'] ) && in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ) { $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true); update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); } } } break; case 'move-up-menu-item' : check_admin_referer( 'move-menu_item' ); $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0; if ( is_nav_menu_item( $menu_item_id ) ) { $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) ); if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) { $menu_id = (int) $menus[0]; $ordered_menu_items = wp_get_nav_menu_items( $menu_id ); $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) ); // set up the data we need in one pass through the array of menu items $dbids_to_orders = array(); $orders_to_dbids = array(); foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) { if ( isset( $ordered_menu_item_object->ID ) ) { if ( isset( $ordered_menu_item_object->menu_order ) ) { $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order; $orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID; } } } // if this menu item is not first if ( ! empty( $dbids_to_orders[$menu_item_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) { // if this menu item is a child of the previous if ( ! empty( $menu_item_data['menu_item_parent'] ) && in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) && isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) && ( $menu_item_data['menu_item_parent'] == $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) { $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0; $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) ); if ( ! is_wp_error( $parent_object ) ) { $parent_data = (array) $parent_object; // if there is something before the parent and parent a child of it, make menu item a child also of it if ( ! empty( $dbids_to_orders[$parent_db_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) && ! empty( $parent_data['menu_item_parent'] ) ) { $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent']; // else if there is something before parent and parent not a child of it, make menu item a child of that something's parent } elseif ( ! empty( $dbids_to_orders[$parent_db_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) ) { $_possible_parent_id = (int) get_post_meta( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1], '_menu_item_menu_item_parent', true); if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) ) $menu_item_data['menu_item_parent'] = $_possible_parent_id; else $menu_item_data['menu_item_parent'] = 0; // else there isn't something before the parent } else { $menu_item_data['menu_item_parent'] = 0; } // set former parent's [menu_order] to that of menu-item's $parent_data['menu_order'] = $parent_data['menu_order'] + 1; // set menu-item's [menu_order] to that of former parent $menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1; // save changes update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); wp_update_post($menu_item_data); wp_update_post($parent_data); } // else this menu item is not a child of the previous } elseif ( empty( $menu_item_data['menu_order'] ) || empty( $menu_item_data['menu_item_parent'] ) || ! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) || empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) || $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] != $menu_item_data['menu_item_parent'] ) { // just make it a child of the previous; keep the order $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]; update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); wp_update_post($menu_item_data); } } } } break; case 'delete-menu-item': $menu_item_id = (int) $_REQUEST['menu-item']; check_admin_referer( 'delete-menu_item_' . $menu_item_id ); if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>'; break; case 'delete': check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id ); if ( is_nav_menu( $nav_menu_selected_id ) ) { $deleted_nav_menu = wp_get_nav_menu_object( $nav_menu_selected_id ); $delete_nav_menu = wp_delete_nav_menu( $nav_menu_selected_id ); if ( is_wp_error($delete_nav_menu) ) { $messages[] = '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>'; } else { // Remove this menu from any locations. $locations = get_theme_mod( 'nav_menu_locations' ); foreach ( (array) $locations as $location => $menu_id ) { if ( $menu_id == $nav_menu_selected_id ) $locations[ $location ] = 0; } set_theme_mod( 'nav_menu_locations', $locations ); $messages[] = '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>'; // Select the next available menu $nav_menu_selected_id = 0; $_nav_menus = wp_get_nav_menus( array('orderby' => 'name') ); foreach( $_nav_menus as $index => $_nav_menu ) { if ( strcmp( $_nav_menu->name, $deleted_nav_menu->name ) >= 0 || $index == count( $_nav_menus ) - 1 ) { $nav_menu_selected_id = $_nav_menu->term_id; break; } } } unset( $delete_nav_menu, $deleted_nav_menu, $_nav_menus ); } else { // Reset the selected menu $nav_menu_selected_id = 0; unset( $_REQUEST['menu'] ); } break; case 'update': check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); // Update menu theme locations if ( isset( $_POST['menu-locations'] ) ) set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) ); // Add Menu if ( 0 == $nav_menu_selected_id ) { $new_menu_title = trim( esc_html( $_POST['menu-name'] ) ); if ( $new_menu_title ) { $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) ); if ( is_wp_error( $_nav_menu_selected_id ) ) { $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; } else { $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); $nav_menu_selected_id = $_nav_menu_selected_id; $nav_menu_selected_title = $_menu_object->name; $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $nav_menu_selected_title ) . '</p></div>'; } } else { $messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>'; } // update existing menu } else { $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id ); $menu_title = trim( esc_html( $_POST['menu-name'] ) ); if ( ! $menu_title ) { $messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>'; $menu_title = $_menu_object->name; } if ( ! is_wp_error( $_menu_object ) ) { $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) ); if ( is_wp_error( $_nav_menu_selected_id ) ) { $_menu_object = $_nav_menu_selected_id; $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; } else { $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); $nav_menu_selected_title = $_menu_object->name; } } // Update menu items if ( ! is_wp_error( $_menu_object ) ) { $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish') ); $menu_items = array(); // Index menu items by db ID foreach( $unsorted_menu_items as $_item ) $menu_items[$_item->db_id] = $_item; $post_fields = array( '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' ); wp_defer_term_counting(true); // Loop through all the menu items' POST variables if ( ! empty( $_POST['menu-item-db-id'] ) ) { foreach( (array) $_POST['menu-item-db-id'] as $_key => $k ) { // Menu item title can't be blank if ( empty( $_POST['menu-item-title'][$_key] ) ) continue; $args = array(); foreach ( $post_fields as $field ) $args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : ''; $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args ); if ( is_wp_error( $menu_item_db_id ) ) $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>'; elseif ( isset( $menu_items[$menu_item_db_id] ) ) unset( $menu_items[$menu_item_db_id] ); } } // Remove menu items from the menu that weren't in $_POST if ( ! empty( $menu_items ) ) { foreach ( array_keys( $menu_items ) as $menu_item_id ) { if ( is_nav_menu_item( $menu_item_id ) ) { wp_delete_post( $menu_item_id ); } } } // Store 'auto-add' pages. $auto_add = ! empty( $_POST['auto-add-pages'] ); $nav_menu_option = (array) get_option( 'nav_menu_options' ); if ( ! isset( $nav_menu_option['auto_add'] ) ) $nav_menu_option['auto_add'] = array(); if ( $auto_add ) { if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) $nav_menu_option['auto_add'][] = $nav_menu_selected_id; } else { if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) ) unset( $nav_menu_option['auto_add'][$key] ); } // Remove nonexistent/deleted menus $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); update_option( 'nav_menu_options', $nav_menu_option ); wp_defer_term_counting(false); do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title ) . '</p></div>'; unset( $menu_items, $unsorted_menu_items ); } } break; } // Get all nav menus $nav_menus = wp_get_nav_menus( array('orderby' => 'name') ); // Get recently edited nav menu $recently_edited = (int) get_user_option( 'nav_menu_recently_edited' ); // If there was no recently edited menu, and $nav_menu_selected_id is a nav menu, update recently edited menu. if ( !$recently_edited && is_nav_menu( $nav_menu_selected_id ) ) { $recently_edited = $nav_menu_selected_id; // Else if $nav_menu_selected_id is not a menu and not requesting that we create a new menu, but $recently_edited is a menu, grab that one. } elseif ( 0 == $nav_menu_selected_id && ! isset( $_REQUEST['menu'] ) && is_nav_menu( $recently_edited ) ) { $nav_menu_selected_id = $recently_edited; // Else try to grab the first menu from the menus list } elseif ( 0 == $nav_menu_selected_id && ! isset( $_REQUEST['menu'] ) && ! empty($nav_menus) ) { $nav_menu_selected_id = $nav_menus[0]->term_id; } // Update the user's setting if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id ); // If there's a menu, get its name. if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) { $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id ); $nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : ''; } // Generate truncated menu names foreach( (array) $nav_menus as $key => $_nav_menu ) { $_nav_menu->truncated_name = trim( wp_html_excerpt( $_nav_menu->name, 40 ) ); if ( $_nav_menu->truncated_name != $_nav_menu->name ) $_nav_menu->truncated_name .= '&hellip;'; $nav_menus[$key]->truncated_name = $_nav_menu->truncated_name; } // Ensure the user will be able to scroll horizontally // by adding a class for the max menu depth. global $_wp_nav_menu_max_depth; $_wp_nav_menu_max_depth = 0; // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth if ( is_nav_menu( $nav_menu_selected_id ) ) $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id ); function wp_nav_menu_max_depth($classes) { global $_wp_nav_menu_max_depth; return "$classes menu-max-depth-$_wp_nav_menu_max_depth"; } add_filter('admin_body_class', 'wp_nav_menu_max_depth'); wp_nav_menu_setup(); wp_initial_nav_menu_meta_boxes(); if ( ! current_theme_supports( 'menus' ) && ! wp_get_nav_menus() ) $messages[] = '<div id="message" class="updated"><p>' . __('The current theme does not natively support menus, but you can use the &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p></div>'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This feature allows you to use a custom menu in place of your theme&#8217;s default menus.') . '</p>' . '<p>' . __('Custom menus may contain links to pages, categories, custom links or other content types (use the Screen Options tab to decide which ones to show on the screen). You can specify a different navigation label for a menu item as well as other attributes. You can create multiple menus. If your theme includes more than one menu, you can choose which custom menu to associate with each. You can also use custom menus in conjunction with the Custom Menus widget.') . '</p>' . '<p>' . __('If your theme does not support the custom menus feature yet (the default themes, Twenty Eleven and Twenty Ten, do), you can learn about adding this support by following the Documentation link to the side.') . '</p>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'create-menus', 'title' => __('Create Menus'), 'content' => '<p>' . __('To create a new custom menu, click on the + tab, give the menu a name, and click Create Menu. Next, add menu items from the appropriate boxes. You&#8217;ll be able to edit the information for each menu item, and can drag and drop to put them in order. You can also drag a menu item a little to the right to make it a submenu, to create menus with hierarchy. Drop the item into its new nested placement when the dotted rectangle target shifts over, also a little to the right. Don&#8217;t forget to click Save when you&#8217;re finished.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Menus_Screen" target="_blank">Documentation on Menus</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); // Get the admin header require_once( './admin-header.php' ); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php esc_html_e('Menus'); ?></h2> <?php foreach( $messages as $message ) : echo $message . "\n"; endforeach; ?> <div id="nav-menus-frame"> <div id="menu-settings-column" class="metabox-holder<?php if ( !$nav_menu_selected_id ) { echo ' metabox-holder-disabled'; } ?>"> <form id="nav-menu-meta" action="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-menu-meta" method="post" enctype="multipart/form-data"> <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> <input type="hidden" name="action" value="add-menu-item" /> <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?> <?php do_meta_boxes( 'nav-menus', 'side', null ); ?> </form> </div><!-- /#menu-settings-column --> <div id="menu-management-liquid"> <div id="menu-management"> <div id="select-nav-menu-container" class="hide-if-js"> <form id="select-nav-menu" action=""> <strong><label for="select-nav-menu"><?php esc_html_e( 'Select Menu:' ); ?></label></strong> <select class="select-nav-menu" name="menu"> <?php foreach( (array) $nav_menus as $_nav_menu ) : ?> <option value="<?php echo esc_attr($_nav_menu->term_id) ?>" <?php selected($nav_menu_selected_id, $_nav_menu->term_id); ?>> <?php echo esc_html( $_nav_menu->truncated_name ); ?> </option> <?php endforeach; ?> <option value="0"><?php esc_html_e('Add New Menu'); ?></option> </select> <input type="hidden" name="action" value="edit" /> <?php submit_button( __( 'Select' ), 'secondary', 'select_menu', false ); ?> </form> </div> <div class="nav-tabs-wrapper"> <div class="nav-tabs"> <?php foreach( (array) $nav_menus as $_nav_menu ) : if ( $nav_menu_selected_id == $_nav_menu->term_id ) : ?><span class="nav-tab nav-tab-active"> <?php echo esc_html( $_nav_menu->truncated_name ); ?> </span><?php else : ?><a href="<?php echo esc_url(add_query_arg( array( 'action' => 'edit', 'menu' => $_nav_menu->term_id, ), admin_url( 'nav-menus.php' ) )); ?>" class="nav-tab hide-if-no-js"> <?php echo esc_html( $_nav_menu->truncated_name ); ?> </a><?php endif; endforeach; if ( 0 == $nav_menu_selected_id ) : ?><span class="nav-tab menu-add-new nav-tab-active"> <?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add menu' ) ); ?> </span><?php else : ?><a href="<?php echo esc_url(add_query_arg( array( 'action' => 'edit', 'menu' => 0, ), admin_url( 'nav-menus.php' ) )); ?>" class="nav-tab menu-add-new"> <?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add menu' ) ); ?> </a><?php endif; ?> </div> </div> <div class="menu-edit"> <form id="update-nav-menu" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data"> <div id="nav-menu-header"> <div id="submitpost" class="submitbox"> <div class="major-publishing-actions"> <label class="menu-name-label howto open-label" for="menu-name"> <span><?php _e('Menu Name'); ?></span> <input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Enter menu name here'); ?>" value="<?php echo esc_attr( $nav_menu_selected_title ); ?>" /> </label> <?php if ( !empty( $nav_menu_selected_id ) ) : if ( ! isset( $auto_add ) ) { $auto_add = get_option( 'nav_menu_options' ); if ( ! isset( $auto_add['auto_add'] ) ) $auto_add = false; elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) ) $auto_add = true; else $auto_add = false; } ?> <div class="auto-add-pages"> <label class="howto"><input type="checkbox"<?php checked( $auto_add ); ?> name="auto-add-pages" value="1" /> <?php printf( __('Automatically add new top-level pages' ), esc_url( admin_url( 'edit.php?post_type=page' ) ) ); ?></label> </div> <?php endif; ?> <br class="clear" /> <div class="publishing-action"> <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'button-primary menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?> </div><!-- END .publishing-action --> <?php if ( ! empty( $nav_menu_selected_id ) ) : ?> <div class="delete-action"> <a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( admin_url('nav-menus.php?action=delete&amp;menu=' . $nav_menu_selected_id), 'delete-nav_menu-' . $nav_menu_selected_id ) ); ?>"><?php _e('Delete Menu'); ?></a> </div><!-- END .delete-action --> <?php endif; ?> </div><!-- END .major-publishing-actions --> </div><!-- END #submitpost .submitbox --> <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' ); ?> <input type="hidden" name="action" value="update" /> <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> </div><!-- END #nav-menu-header --> <div id="post-body"> <div id="post-body-content"> <?php if ( isset( $edit_markup ) ) { if ( ! is_wp_error( $edit_markup ) ) echo $edit_markup; } else if ( empty( $nav_menu_selected_id ) ) { echo '<div class="post-body-plain">'; echo '<p>' . __('To create a custom menu, give it a name above and click Create Menu. Then choose items like pages, categories or custom links from the left column to add to this menu.') . '</p>'; echo '<p>' . __('After you have added your items, drag and drop to put them in the order you want. You can also click each item to reveal additional configuration options.') . '</p>'; echo '<p>' . __('When you have finished building your custom menu, make sure you click the Save Menu button.') . '</p>'; echo '</div>'; } ?> </div><!-- /#post-body-content --> </div><!-- /#post-body --> <div id="nav-menu-footer"> <div class="major-publishing-actions"> <div class="publishing-action"> <?php if ( ! empty( $nav_menu_selected_id ) ) submit_button( __( 'Save Menu' ), 'button-primary menu-save', 'save_menu', false, array( 'id' => 'save_menu_footer' ) ); ?> </div> </div> </div><!-- /#nav-menu-footer --> </form><!-- /#update-nav-menu --> </div><!-- /.menu-edit --> </div><!-- /#menu-management --> </div><!-- /#menu-management-liquid --> </div><!-- /#nav-menus-frame --> </div><!-- /.wrap--> <?php include( './admin-footer.php' ); ?>
01happy-blog
trunk/myblog/wp-admin/nav-menus.php
PHP
oos
28,122
<?php /** * Options Management Administration Screen. * * If accessed directly in a browser this page shows a list of all saved options * along with editable fields for their values. Serialized data is not supported * and there is no way to remove options via this page. It is not linked to from * anywhere else in the admin. * * This file is also the target of the forms in core and custom options pages * that use the Settings API. In this case it saves the new option values * and returns the user to their page of origin. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); $title = __('Settings'); $this_file = 'options.php'; $parent_file = 'options-general.php'; wp_reset_vars(array('action', 'option_page')); $capability = 'manage_options'; if ( empty($option_page) ) // This is for back compat and will eventually be removed. $option_page = 'options'; else $capability = apply_filters( "option_page_capability_{$option_page}", $capability ); if ( !current_user_can( $capability ) ) wp_die(__('Cheatin&#8217; uh?')); // Handle admin email change requests if ( is_multisite() ) { if ( ! empty($_GET[ 'adminhash' ] ) ) { $new_admin_details = get_option( 'adminhash' ); $redirect = 'options-general.php?updated=false'; if ( is_array( $new_admin_details ) && $new_admin_details[ 'hash' ] == $_GET[ 'adminhash' ] && !empty($new_admin_details[ 'newemail' ]) ) { update_option( 'admin_email', $new_admin_details[ 'newemail' ] ); delete_option( 'adminhash' ); delete_option( 'new_admin_email' ); $redirect = 'options-general.php?updated=true'; } wp_redirect( admin_url( $redirect ) ); exit; } elseif ( ! empty( $_GET['dismiss'] ) && 'new_admin_email' == $_GET['dismiss'] ) { delete_option( 'adminhash' ); delete_option( 'new_admin_email' ); wp_redirect( admin_url( 'options-general.php?updated=true' ) ); exit; } } if ( is_multisite() && !is_super_admin() && 'update' != $action ) wp_die(__('Cheatin&#8217; uh?')); $whitelist_options = array( 'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string' ), 'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ), 'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type', 'embed_autourls', 'embed_size_w', 'embed_size_h' ), 'privacy' => array( 'blog_public' ), 'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'show_on_front', 'page_on_front', 'page_for_posts' ), 'writing' => array( 'default_post_edit_rows', 'use_smilies', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'default_post_format', 'enable_app', 'enable_xmlrpc' ), 'options' => array( '' ) ); $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass'); $uploads_options = array('uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path'); if ( !is_multisite() ) { if ( !defined( 'WP_SITEURL' ) ) $whitelist_options['general'][] = 'siteurl'; if ( !defined( 'WP_HOME' ) ) $whitelist_options['general'][] = 'home'; $whitelist_options['general'][] = 'admin_email'; $whitelist_options['general'][] = 'users_can_register'; $whitelist_options['general'][] = 'default_role'; $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options); $whitelist_options['writing'][] = 'ping_sites'; $whitelist_options['media'] = array_merge($whitelist_options['media'], $uploads_options); } else { $whitelist_options['general'][] = 'new_admin_email'; $whitelist_options['general'][] = 'WPLANG'; $whitelist_options['general'][] = 'language'; if ( apply_filters( 'enable_post_by_email_configuration', true ) ) $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options); $whitelist_options[ 'misc' ] = array(); } $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options ); /* * If $_GET['action'] == 'update' we are saving settings sent from a settings page */ if ( 'update' == $action ) { if ( 'options' == $option_page && !isset( $_POST['option_page'] ) ) { // This is for back compat and will eventually be removed. $unregistered = true; check_admin_referer( 'update-options' ); } else { $unregistered = false; check_admin_referer( $option_page . '-options' ); } if ( !isset( $whitelist_options[ $option_page ] ) ) wp_die( __( '<strong>ERROR</strong>: options page not found.' ) ); if ( 'options' == $option_page ) { if ( is_multisite() && ! is_super_admin() ) wp_die( __( 'You do not have sufficient permissions to modify unregistered settings for this site.' ) ); $options = explode( ',', stripslashes( $_POST[ 'page_options' ] ) ); } else { $options = $whitelist_options[ $option_page ]; } // Handle custom date/time formats if ( 'general' == $option_page ) { if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['date_format'] ) ) $_POST['date_format'] = $_POST['date_format_custom']; if ( !empty($_POST['time_format']) && isset($_POST['time_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['time_format'] ) ) $_POST['time_format'] = $_POST['time_format_custom']; // Map UTC+- timezones to gmt_offsets and set timezone_string to empty. if ( !empty($_POST['timezone_string']) && preg_match('/^UTC[+-]/', $_POST['timezone_string']) ) { $_POST['gmt_offset'] = $_POST['timezone_string']; $_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']); $_POST['timezone_string'] = ''; } } if ( $options ) { foreach ( $options as $option ) { if ( $unregistered ) _deprecated_argument( 'options.php', '2.7', sprintf( __( 'The <code>%1$s</code> setting is unregistered. Unregistered settings are deprecated. See http://codex.wordpress.org/Settings_API' ), $option, $option_page ) ); $option = trim($option); $value = null; if ( isset($_POST[$option]) ) $value = $_POST[$option]; if ( !is_array($value) ) $value = trim($value); $value = stripslashes_deep($value); update_option($option, $value); } } /** * Handle settings errors and return to options page */ // If no settings errors were registered add a general 'updated' message. if ( !count( get_settings_errors() ) ) add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); set_transient('settings_errors', get_settings_errors(), 30); /** * Redirect back to the settings page that was submitted */ $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() ); wp_redirect( $goback ); exit; } include('./admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php esc_html_e('All Settings'); ?></h2> <form name="form" action="options.php" method="post" id="all-options"> <?php wp_nonce_field('options-options') ?> <input type="hidden" name="action" value="update" /> <input type='hidden' name='option_page' value='options' /> <table class="form-table"> <?php $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" ); foreach ( (array) $options as $option ) : $disabled = false; if ( $option->option_name == '' ) continue; if ( is_serialized( $option->option_value ) ) { if ( is_serialized_string( $option->option_value ) ) { // this is a serialized string, so we should display it $value = maybe_unserialize( $option->option_value ); $options_to_update[] = $option->option_name; $class = 'all-options'; } else { $value = 'SERIALIZED DATA'; $disabled = true; $class = 'all-options disabled'; } } else { $value = $option->option_value; $options_to_update[] = $option->option_name; $class = 'all-options'; } $name = esc_attr( $option->option_name ); echo " <tr> <th scope='row'><label for='$name'>" . esc_html( $option->option_name ) . "</label></th> <td>"; if ( strpos( $value, "\n" ) !== false ) echo "<textarea class='$class' name='$name' id='$name' cols='30' rows='5'>" . esc_textarea( $value ) . "</textarea>"; else echo "<input class='regular-text $class' type='text' name='$name' id='$name' value='" . esc_attr( $value ) . "'" . disabled( $disabled, true, false ) . " />"; echo "</td> </tr>"; endforeach; ?> </table> <input type="hidden" name="page_options" value="<?php echo esc_attr( implode( ',', $options_to_update ) ); ?>" /> <?php submit_button( __( 'Save Changes' ), 'primary', 'Update' ); ?> </form> </div> <?php include('./admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/options.php
PHP
oos
9,224
<?php /** * New User Administration Screen. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); if ( is_multisite() ) { if ( ! current_user_can( 'create_users' ) && ! current_user_can( 'promote_users' ) ) wp_die( __( 'Cheatin&#8217; uh?' ) ); } elseif ( ! current_user_can( 'create_users' ) ) { wp_die( __( 'Cheatin&#8217; uh?' ) ); } if ( is_multisite() ) { function admin_created_user_email( $text ) { /* translators: 1: Site name, 2: site URL, 3: role */ return sprintf( __( 'Hi, You\'ve been invited to join \'%1$s\' at %2$s with the role of %3$s. If you do not want to join this site please ignore this email. This invitation will expire in a few days. Please click the following link to activate your user account: %%s' ), get_bloginfo('name'), home_url(), esc_html( $_REQUEST[ 'role' ] ) ); } add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' ); function admin_created_user_subject( $text ) { return sprintf( __( '[%s] Your site invite' ), get_bloginfo( 'name' ) ); } } if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) { check_admin_referer( 'add-user', '_wpnonce_add-user' ); $user_details = null; if ( false !== strpos($_REQUEST[ 'email' ], '@') ) { $user_details = get_user_by('email', $_REQUEST[ 'email' ]); } else { if ( is_super_admin() ) { $user_details = get_user_by('login', $_REQUEST[ 'email' ]); } else { wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) ); die(); } } if ( !$user_details ) { wp_redirect( add_query_arg( array('update' => 'does_not_exist'), 'user-new.php' ) ); die(); } if ( ! current_user_can('promote_user', $user_details->ID) ) wp_die(__('Cheatin&#8217; uh?')); // Adding an existing user to this blog $new_user_email = $user_details->user_email; $redirect = 'user-new.php'; $username = $user_details->user_login; $user_id = $user_details->ID; if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) { $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' ); } else { if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) ); $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); } else { $newuser_key = substr( md5( $user_id ), 0, 5 ); add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) ); /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */ $message = __( 'Hi, You\'ve been invited to join \'%1$s\' at %2$s with the role of %3$s. Please click the following link to confirm the invite: %4$s' ); wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ), sprintf($message, get_option('blogname'), home_url(), $_REQUEST[ 'role' ], home_url("/newbloguser/$newuser_key/"))); $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' ); } } wp_redirect( $redirect ); die(); } elseif ( isset($_REQUEST['action']) && 'createuser' == $_REQUEST['action'] ) { check_admin_referer( 'create-user', '_wpnonce_create-user' ); if ( ! current_user_can('create_users') ) wp_die(__('Cheatin&#8217; uh?')); if ( ! is_multisite() ) { $user_id = edit_user(); if ( is_wp_error( $user_id ) ) { $add_user_errors = $user_id; } else { if ( current_user_can( 'list_users' ) ) $redirect = 'users.php?update=add&id=' . $user_id; else $redirect = add_query_arg( 'update', 'add', 'user-new.php' ); wp_redirect( $redirect ); die(); } } else { // Adding a new user to this blog $user_details = wpmu_validate_user_signup( $_REQUEST[ 'user_login' ], $_REQUEST[ 'email' ] ); unset( $user_details[ 'errors' ]->errors[ 'user_email_used' ] ); if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) { $add_user_errors = $user_details[ 'errors' ]; } else { $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true)); if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email } wpmu_signup_user( $new_user_login, $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) ); if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $_REQUEST[ 'email' ] ) ); wpmu_activate_signup( $key ); $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' ); } else { $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' ); } wp_redirect( $redirect ); die(); } } } $title = __('Add New User'); $parent_file = 'users.php'; $do_both = false; if ( is_multisite() && current_user_can('promote_users') && current_user_can('create_users') ) $do_both = true; $help = '<p>' . __('To add a new user to your site, fill in the form on this screen and click the Add New User button at the bottom.') . '</p>'; if ( is_multisite() ) { $help .= '<p>' . __('Because this is a multisite installation, you may add accounts that already exist on the Network by specifying a username or email, and defining a role. For more options, such as specifying a password, you have to be a Network Administrator and use the hover link under an existing user&#8217;s name to Edit the user profile under Network Admin > All Users.') . '</p>' . '<p>' . __('New users will receive an email letting them know they&#8217;ve been added as a user for your site. This email will also contain their password. Check the box if you don&#8217;t want the user to receive a welcome email.') . '</p>'; } else { $help .= '<p>' . __('You must assign a password to the new user, which they can change after logging in. The username, however, cannot be changed.') . '</p>' . '<p>' . __('New users will receive an email letting them know they&#8217;ve been added as a user for your site. By default, this email will also contain their password. Uncheck the box if you don&#8217;t want the password to be included in the welcome email.') . '</p>'; } $help .= '<p>' . __('Remember to click the Add New User button at the bottom of this screen when you are finished.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => $help, ) ); get_current_screen()->add_help_tab( array( 'id' => 'user-roles', 'title' => __('User Roles'), 'content' => '<p>' . __('Here is a basic overview of the different user roles and the permissions associated with each one:') . '</p>' . '<ul>' . '<li>' . __('Administrators have access to all the administration features.') . '</li>' . '<li>' . __('Editors can publish posts, manage posts as well as manage other people&#8217;s posts, etc.') . '</li>' . '<li>' . __('Authors can publish and manage their own posts, and are able to upload files.') . '</li>' . '<li>' . __('Contributors can write and manage their posts but not publish posts or upload media files.') . '</li>' . '<li>' . __('Subscribers can read comments/comment/receive newsletters, etc. but cannot create regular site content.') . '</li>' . '</ul>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Users_Add_New_Screen" target="_blank">Documentation on Adding New Users</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); wp_enqueue_script('wp-ajax-response'); wp_enqueue_script('user-profile'); if ( is_multisite() && current_user_can( 'promote_users' ) && ! wp_is_large_network( 'users' ) && ( is_super_admin() || apply_filters( 'autocomplete_users_for_site_admins', false ) ) ) { wp_enqueue_script( 'user-suggest' ); } require_once( 'admin-header.php' ); if ( isset($_GET['update']) ) { $messages = array(); if ( is_multisite() ) { switch ( $_GET['update'] ) { case "newuserconfimation": $messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.'); break; case "add": $messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.'); break; case "addnoconfirmation": $messages[] = __('User has been added to your site.'); break; case "addexisting": $messages[] = __('That user is already a member of this site.'); break; case "does_not_exist": $messages[] = __('The requested user does not exist.'); break; case "does_not_exist": $messages[] = __('Please enter a valid email address.'); break; } } else { if ( 'add' == $_GET['update'] ) $messages[] = __('User added.'); } } ?> <div class="wrap"> <?php screen_icon(); ?> <h2 id="add-new-user"> <?php if ( current_user_can( 'create_users' ) ) { echo _x( 'Add New User', 'user' ); } elseif ( current_user_can( 'promote_users' ) ) { echo _x( 'Add Existing User', 'user' ); } ?> </h2> <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?> <div class="error"> <ul> <?php foreach ( $errors->get_error_messages() as $err ) echo "<li>$err</li>\n"; ?> </ul> </div> <?php endif; if ( ! empty( $messages ) ) { foreach ( $messages as $msg ) echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; } ?> <?php if ( isset($add_user_errors) && is_wp_error( $add_user_errors ) ) : ?> <div class="error"> <?php foreach ( $add_user_errors->get_error_messages() as $message ) echo "<p>$message</p>"; ?> </div> <?php endif; ?> <div id="ajax-response"></div> <?php if ( is_multisite() ) { if ( $do_both ) echo '<h3 id="add-existing-user">' . __('Add Existing User') . '</h3>'; if ( !is_super_admin() ) { _e( 'Enter the email address of an existing user on this network to invite them to this site. That person will be sent an email asking them to confirm the invite.' ); $label = __('E-mail'); } else { _e( 'Enter the email address or username of an existing user on this network to invite them to this site. That person will be sent an email asking them to confirm the invite.' ); $label = __('E-mail or Username'); } ?> <form action="" method="post" name="adduser" id="adduser" class="add:users: validate"<?php do_action('user_new_form_tag');?>> <input name="action" type="hidden" value="adduser" /> <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ) ?> <table class="form-table"> <tr class="form-field form-required"> <th scope="row"><label for="adduser-email"><?php echo $label; ?></label></th> <td><input name="email" type="text" id="adduser-email" class="wp-suggest-user" value="" /></td> </tr> <tr class="form-field"> <th scope="row"><label for="adduser-role"><?php _e('Role'); ?></label></th> <td><select name="role" id="adduser-role"> <?php wp_dropdown_roles( get_option('default_role') ); ?> </select> </td> </tr> <?php if ( is_super_admin() ) { ?> <tr> <th scope="row"><label for="adduser-noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th> <td><label for="adduser-noconfirmation"><input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1" /> <?php _e( 'Add the user without sending them a confirmation email.' ); ?></label></td> </tr> <?php } ?> </table> <?php submit_button( __( 'Add Existing User '), 'primary', 'adduser', true, array( 'id' => 'addusersub' ) ); ?> </form> <?php } // is_multisite() if ( current_user_can( 'create_users') ) { if ( $do_both ) echo '<h3 id="create-new-user">' . __( 'Add New User' ) . '</h3>'; ?> <p><?php _e('Create a brand new user and add it to this site.'); ?></p> <form action="" method="post" name="createuser" id="createuser" class="add:users: validate"<?php do_action('user_new_form_tag');?>> <input name="action" type="hidden" value="createuser" /> <?php wp_nonce_field( 'create-user', '_wpnonce_create-user' ) ?> <?php // Load up the passed data, else set to a default. foreach ( array( 'user_login' => 'login', 'first_name' => 'firstname', 'last_name' => 'lastname', 'email' => 'email', 'url' => 'uri', 'role' => 'role', 'send_password' => 'send_password', 'noconfirmation' => 'ignore_pass' ) as $post_field => $var ) { $var = "new_user_$var"; if( isset( $_POST['createuser'] ) ) { if ( ! isset($$var) ) $$var = isset( $_POST[$post_field] ) ? stripslashes( $_POST[$post_field] ) : ''; } else { $$var = false; } } ?> <table class="form-table"> <tr class="form-field form-required"> <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td> </tr> <tr class="form-field form-required"> <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> <td><input name="email" type="text" id="email" value="<?php echo esc_attr($new_user_email); ?>" /></td> </tr> <?php if ( !is_multisite() ) { ?> <tr class="form-field"> <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th> <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td> </tr> <tr class="form-field"> <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th> <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td> </tr> <tr class="form-field"> <th scope="row"><label for="url"><?php _e('Website') ?></label></th> <td><input name="url" type="text" id="url" class="code" value="<?php echo esc_attr($new_user_uri); ?>" /></td> </tr> <?php if ( apply_filters('show_password_fields', true) ) : ?> <tr class="form-field form-required"> <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, required)'); ?></span></label></th> <td><input name="pass1" type="password" id="pass1" autocomplete="off" /> <br /> <input name="pass2" type="password" id="pass2" autocomplete="off" /> <br /> <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div> <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p> </td> </tr> <tr> <th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th> <td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" <?php checked( $new_user_send_password ); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td> </tr> <?php endif; ?> <?php } // !is_multisite ?> <tr class="form-field"> <th scope="row"><label for="role"><?php _e('Role'); ?></label></th> <td><select name="role" id="role"> <?php if ( !$new_user_role ) $new_user_role = !empty($current_role) ? $current_role : get_option('default_role'); wp_dropdown_roles($new_user_role); ?> </select> </td> </tr> <?php if ( is_multisite() && is_super_admin() ) { ?> <tr> <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th> <td><label for="noconfirmation"><input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" <?php checked( $new_user_ignore_pass ); ?> /> <?php _e( 'Add the user without sending them a confirmation email.' ); ?></label></td> </tr> <?php } ?> </table> <?php submit_button( __( 'Add New User '), 'primary', 'createuser', true, array( 'id' => 'createusersub' ) ); ?> </form> <?php } // current_user_can('create_users') ?> </div> <?php include('./admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/user-new.php
PHP
oos
16,417
<?php /** * WordPress Installer * * @package WordPress * @subpackage Administration */ // Sanity check. if ( false ) { ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Error: PHP is not running</title> </head> <body> <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png?ver=20120216" /></h1> <h2>Error: PHP is not running</h2> <p>WordPress requires that your web server is running PHP. Your server does not have PHP installed, or PHP is turned off.</p> </body> </html> <?php } /** * We are installing WordPress. * * @since 1.5.1 * @var bool */ define( 'WP_INSTALLING', true ); /** Load WordPress Bootstrap */ require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' ); /** Load WordPress Administration Upgrade API */ require_once( dirname( __FILE__ ) . '/includes/upgrade.php' ); /** Load wpdb */ require_once(dirname(dirname(__FILE__)) . '/wp-includes/wp-db.php'); $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0; /** * Display install header. * * @since 2.5.0 * @package WordPress * @subpackage Installer */ function display_header() { header( 'Content-Type: text/html; charset=utf-8' ); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php _e( 'WordPress &rsaquo; Installation' ); ?></title> <?php wp_admin_css( 'install', true ); ?> </head> <body<?php if ( is_rtl() ) echo ' class="rtl"'; ?>> <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png?ver=20120216" /></h1> <?php } // end display_header() /** * Display installer setup form. * * @since 2.8.0 * @package WordPress * @subpackage Installer */ function display_setup_form( $error = null ) { global $wpdb; $user_table = ( $wpdb->get_var("SHOW TABLES LIKE '$wpdb->users'") != null ); // Ensure that Blogs appear in search engines by default $blog_public = 1; if ( ! empty( $_POST ) ) $blog_public = isset( $_POST['blog_public'] ); $weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : ''; $user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin'; $admin_password = isset($_POST['admin_password']) ? trim( stripslashes( $_POST['admin_password'] ) ) : ''; $admin_email = isset( $_POST['admin_email'] ) ? trim( stripslashes( $_POST['admin_email'] ) ) : ''; if ( ! is_null( $error ) ) { ?> <p class="message"><?php printf( __( '<strong>ERROR</strong>: %s' ), $error ); ?></p> <?php } ?> <form id="setup" method="post" action="install.php?step=2"> <table class="form-table"> <tr> <th scope="row"><label for="weblog_title"><?php _e( 'Site Title' ); ?></label></th> <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td> </tr> <tr> <th scope="row"><label for="user_name"><?php _e('Username'); ?></label></th> <td> <?php if ( $user_table ) { _e('User(s) already exists.'); } else { ?><input name="user_name" type="text" id="user_login" size="25" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" /> <p><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods and the @ symbol.' ); ?></p> <?php } ?> </td> </tr> <?php if ( ! $user_table ) : ?> <tr> <th scope="row"> <label for="admin_password"><?php _e('Password, twice'); ?></label> <p><?php _e('A password will be automatically generated for you if you leave this blank.'); ?></p> </th> <td> <input name="admin_password" type="password" id="pass1" size="25" value="" /> <p><input name="admin_password2" type="password" id="pass2" size="25" value="" /></p> <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div> <p><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p> </td> </tr> <?php endif; ?> <tr> <th scope="row"><label for="admin_email"><?php _e( 'Your E-mail' ); ?></label></th> <td><input name="admin_email" type="text" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" /> <p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td> </tr> <tr> <th scope="row"><label for="blog_public"><?php _e( 'Privacy' ); ?></label></th> <td colspan="2"><label><input type="checkbox" name="blog_public" value="1" <?php checked( $blog_public ); ?> /> <?php _e( 'Allow search engines to index this site.' ); ?></label></td> </tr> </table> <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install WordPress' ); ?>" class="button" /></p> </form> <?php } // end display_setup_form() // Let's check to make sure WP isn't already installed. if ( is_blog_installed() ) { display_header(); die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p><p class="step"><a href="../wp-login.php" class="button">' . __('Log In') . '</a></p></body></html>' ); } $php_version = phpversion(); $mysql_version = $wpdb->db_version(); $php_compat = version_compare( $php_version, $required_php_version, '>=' ); $mysql_compat = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' ); if ( !$mysql_compat && !$php_compat ) $compat = sprintf( __( 'You cannot install because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.' ), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ); elseif ( !$php_compat ) $compat = sprintf( __( 'You cannot install because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher. You are running version %3$s.' ), $wp_version, $required_php_version, $php_version ); elseif ( !$mysql_compat ) $compat = sprintf( __( 'You cannot install because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires MySQL version %2$s or higher. You are running version %3$s.' ), $wp_version, $required_mysql_version, $mysql_version ); if ( !$mysql_compat || !$php_compat ) { display_header(); die( '<h1>' . __( 'Insufficient Requirements' ) . '</h1><p>' . $compat . '</p></body></html>' ); } if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) { display_header(); die( '<h1>' . __( 'Configuration Error' ) . '</h1><p>' . __( 'Your <code>wp-config.php</code> file has an empty database table prefix, which is not supported.' ) . '</p></body></html>' ); } switch($step) { case 0: // Step 1 case 1: // Step 1, direct link. display_header(); ?> <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1> <p><?php printf( __( 'Welcome to the famous five minute WordPress installation process! You may want to browse the <a href="%s">ReadMe documentation</a> at your leisure. Otherwise, just fill in the information below and you&#8217;ll be on your way to using the most extendable and powerful personal publishing platform in the world.' ), '../readme.html' ); ?></p> <h1><?php _e( 'Information needed' ); ?></h1> <p><?php _e( 'Please provide the following information. Don&#8217;t worry, you can always change these settings later.' ); ?></p> <?php display_setup_form(); break; case 2: if ( ! empty( $wpdb->error ) ) wp_die( $wpdb->error->get_error_message() ); display_header(); // Fill in the data we gathered $weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : ''; $user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin'; $admin_password = isset($_POST['admin_password']) ? $_POST['admin_password'] : ''; $admin_password_check = isset($_POST['admin_password2']) ? $_POST['admin_password2'] : ''; $admin_email = isset( $_POST['admin_email'] ) ?trim( stripslashes( $_POST['admin_email'] ) ) : ''; $public = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 0; // check e-mail address $error = false; if ( empty( $user_name ) ) { // TODO: poka-yoke display_setup_form( __('you must provide a valid username.') ); $error = true; } elseif ( $user_name != sanitize_user( $user_name, true ) ) { display_setup_form( __('the username you provided has invalid characters.') ); $error = true; } elseif ( $admin_password != $admin_password_check ) { // TODO: poka-yoke display_setup_form( __( 'your passwords do not match. Please try again' ) ); $error = true; } else if ( empty( $admin_email ) ) { // TODO: poka-yoke display_setup_form( __( 'you must provide an e-mail address.' ) ); $error = true; } elseif ( ! is_email( $admin_email ) ) { // TODO: poka-yoke display_setup_form( __( 'that isn&#8217;t a valid e-mail address. E-mail addresses look like: <code>username@example.com</code>' ) ); $error = true; } if ( $error === false ) { $wpdb->show_errors(); $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password); extract( $result, EXTR_SKIP ); ?> <h1><?php _e( 'Success!' ); ?></h1> <p><?php _e( 'WordPress has been installed. Were you expecting more steps? Sorry to disappoint.' ); ?></p> <table class="form-table install-success"> <tr> <th><?php _e( 'Username' ); ?></th> <td><?php echo esc_html( sanitize_user( $user_name, true ) ); ?></td> </tr> <tr> <th><?php _e( 'Password' ); ?></th> <td><?php if ( ! empty( $password ) && empty($admin_password_check) ) echo '<code>'. esc_html($password) .'</code><br />'; echo "<p>$password_message</p>"; ?> </td> </tr> </table> <p class="step"><a href="../wp-login.php" class="button"><?php _e( 'Log In' ); ?></a></p> <?php } break; } ?> <script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script> <?php wp_print_scripts( 'user-profile' ); ?> </body> </html>
01happy-blog
trunk/myblog/wp-admin/install.php
PHP
oos
10,353
<?php /** * WordPress Export Administration Screen * * @package WordPress * @subpackage Administration */ /** Load WordPress Bootstrap */ require_once ('admin.php'); if ( !current_user_can('export') ) wp_die(__('You do not have sufficient permissions to export the content of this site.')); /** Load WordPress export API */ require_once('./includes/export.php'); $title = __('Export'); function add_js() { ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready(function($){ var form = $('#export-filters'), filters = form.find('.export-filters'); filters.hide(); form.find('input:radio').change(function() { filters.slideUp('fast'); switch ( $(this).val() ) { case 'posts': $('#post-filters').slideDown(); break; case 'pages': $('#page-filters').slideDown(); break; } }); }); //]]> </script> <?php } add_action( 'admin_head', 'add_js' ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('You can export a file of your site&#8217;s content in order to import it into another installation or platform. The export file will be an XML file format called WXR. Posts, pages, comments, custom fields, categories, and tags can be included. You can choose for the WXR file to include only certain posts or pages by setting the dropdown filters to limit the export by category, author, date range by month, or publishing status.') . '</p>' . '<p>' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '</p>', ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Tools_Export_Screen" target="_blank">Documentation on Export</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); if ( isset( $_GET['download'] ) ) { $args = array(); if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) { $args['content'] = 'all'; } else if ( 'posts' == $_GET['content'] ) { $args['content'] = 'post'; if ( $_GET['cat'] ) $args['category'] = (int) $_GET['cat']; if ( $_GET['post_author'] ) $args['author'] = (int) $_GET['post_author']; if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) { $args['start_date'] = $_GET['post_start_date']; $args['end_date'] = $_GET['post_end_date']; } if ( $_GET['post_status'] ) $args['status'] = $_GET['post_status']; } else if ( 'pages' == $_GET['content'] ) { $args['content'] = 'page'; if ( $_GET['page_author'] ) $args['author'] = (int) $_GET['page_author']; if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) { $args['start_date'] = $_GET['page_start_date']; $args['end_date'] = $_GET['page_end_date']; } if ( $_GET['page_status'] ) $args['status'] = $_GET['page_status']; } else { $args['content'] = $_GET['content']; } export_wp( $args ); die(); } require_once ('admin-header.php'); function export_date_options( $post_type = 'post' ) { global $wpdb, $wp_locale; $months = $wpdb->get_results( $wpdb->prepare( " SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts WHERE post_type = %s AND post_status != 'auto-draft' ORDER BY post_date DESC ", $post_type ) ); $month_count = count( $months ); if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) return; foreach ( $months as $date ) { if ( 0 == $date->year ) continue; $month = zeroise( $date->month, 2 ); echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>'; } } ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p> <p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.'); ?></p> <p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function in another WordPress installation to import the content from this site.'); ?></p> <h3><?php _e( 'Choose what to export' ); ?></h3> <form action="" method="get" id="export-filters"> <input type="hidden" name="download" value="true" /> <p><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label></p> <p class="description"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></p> <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p> <ul id="post-filters" class="export-filters"> <li> <label><?php _e( 'Categories:' ); ?></label> <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?> </li> <li> <label><?php _e( 'Authors:' ); ?></label> <?php $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" ); wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) ); ?> </li> <li> <label><?php _e( 'Date range:' ); ?></label> <select name="post_start_date"> <option value="0"><?php _e( 'Start Date' ); ?></option> <?php export_date_options(); ?> </select> <select name="post_end_date"> <option value="0"><?php _e( 'End Date' ); ?></option> <?php export_date_options(); ?> </select> </li> <li> <label><?php _e( 'Status:' ); ?></label> <select name="post_status"> <option value="0"><?php _e( 'All' ); ?></option> <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' ); foreach ( $post_stati as $status ) : ?> <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option> <?php endforeach; ?> </select> </li> </ul> <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p> <ul id="page-filters" class="export-filters"> <li> <label><?php _e( 'Authors:' ); ?></label> <?php $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" ); wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) ); ?> </li> <li> <label><?php _e( 'Date range:' ); ?></label> <select name="page_start_date"> <option value="0"><?php _e( 'Start Date' ); ?></option> <?php export_date_options( 'page' ); ?> </select> <select name="page_end_date"> <option value="0"><?php _e( 'End Date' ); ?></option> <?php export_date_options( 'page' ); ?> </select> </li> <li> <label><?php _e( 'Status:' ); ?></label> <select name="page_status"> <option value="0"><?php _e( 'All' ); ?></option> <?php foreach ( $post_stati as $status ) : ?> <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option> <?php endforeach; ?> </select> </li> </ul> <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?> <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p> <?php endforeach; ?> <?php submit_button( __('Download Export File'), 'secondary' ); ?> </form> </div> <?php include('admin-footer.php'); ?>
01happy-blog
trunk/myblog/wp-admin/export.php
PHP
oos
7,647
<?php /** * Administration Functions * * This file is deprecated, use 'wp-admin/includes/admin.php' instead. * * @deprecated 2.5 * @package WordPress * @subpackage Administration */ _deprecated_file( basename(__FILE__), '2.5', 'wp-admin/includes/admin.php' ); /** WordPress Administration API: Includes all Administration functions. */ require_once(ABSPATH . 'wp-admin/includes/admin.php');
01happy-blog
trunk/myblog/wp-admin/admin-functions.php
PHP
oos
401
<?php /** * User Profile Administration Screen. * * @package WordPress * @subpackage Administration */ /** * This is a profile page. * * @since 2.5.0 * @var bool */ define('IS_PROFILE_PAGE', true); /** Load User Editing Page */ require_once('./user-edit.php');
01happy-blog
trunk/myblog/wp-admin/profile.php
PHP
oos
273
<?php /** * Edit links form for inclusion in administration panels. * * @package WordPress * @subpackage Administration */ // don't load directly if ( !defined('ABSPATH') ) die('-1'); if ( ! empty($link_id) ) { $heading = sprintf( __( '<a href="%s">Links</a> / Edit Link' ), 'link-manager.php' ); $submit_text = __('Update Link'); $form = '<form name="editlink" id="editlink" method="post" action="link.php">'; $nonce_action = 'update-bookmark_' . $link_id; } else { $heading = sprintf( __( '<a href="%s">Links</a> / Add New Link' ), 'link-manager.php' ); $submit_text = __('Add Link'); $form = '<form name="addlink" id="addlink" method="post" action="link.php">'; $nonce_action = 'add-bookmark'; } require_once('./includes/meta-boxes.php'); add_meta_box('linksubmitdiv', __('Save'), 'link_submit_meta_box', null, 'side', 'core'); add_meta_box('linkcategorydiv', __('Categories'), 'link_categories_meta_box', null, 'normal', 'core'); add_meta_box('linktargetdiv', __('Target'), 'link_target_meta_box', null, 'normal', 'core'); add_meta_box('linkxfndiv', __('Link Relationship (XFN)'), 'link_xfn_meta_box', null, 'normal', 'core'); add_meta_box('linkadvanceddiv', __('Advanced'), 'link_advanced_meta_box', null, 'normal', 'core'); do_action('add_meta_boxes', 'link', $link); do_action('add_meta_boxes_link', $link); do_action('do_meta_boxes', 'link', 'normal', $link); do_action('do_meta_boxes', 'link', 'advanced', $link); do_action('do_meta_boxes', 'link', 'side', $link); add_screen_option('layout_columns', array('max' => 2, 'default' => 2) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __( 'You can add or edit links on this screen by entering information in each of the boxes. Only the link&#8217;s web address and name (the text you want to display on your site as the link) are required fields.' ) . '</p>' . '<p>' . __( 'The boxes for link name, web address, and description have fixed positions, while the others may be repositioned using drag and drop. You can also hide boxes you don&#8217;t use in the Screen Options tab, or minimize boxes by clicking on the title bar of the box.' ) . '</p>' . '<p>' . __( 'XFN stands for <a href="http://gmpg.org/xfn/" target="_blank">XHTML Friends Network</a>, which is optional. WordPress allows the generation of XFN attributes to show how you are related to the authors/owners of the site to which you are linking.' ) . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . '<p>' . __( '<a href="http://codex.wordpress.org/Links_Add_New_Screen" target="_blank">Documentation on Creating Links</a>' ) . '</p>' . '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' ); require_once ('admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?> <a href="link-add.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'link'); ?></a></h2> <?php if ( isset( $_GET['added'] ) ) : ?> <div id="message" class="updated"><p><?php _e('Link added.'); ?></p></div> <?php endif; ?> <?php if ( !empty($form) ) echo $form; if ( !empty($link_added) ) echo $link_added; wp_nonce_field( $nonce_action ); wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> <div id="poststuff"> <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> <div id="post-body-content"> <div id="namediv" class="stuffbox"> <h3><label for="link_name"><?php _ex('Name', 'link name') ?></label></h3> <div class="inside"> <input type="text" name="link_name" size="30" tabindex="1" value="<?php echo esc_attr($link->link_name); ?>" id="link_name" /> <p><?php _e('Example: Nifty blogging software'); ?></p> </div> </div> <div id="addressdiv" class="stuffbox"> <h3><label for="link_url"><?php _e('Web Address') ?></label></h3> <div class="inside"> <input type="text" name="link_url" size="30" class="code" tabindex="1" value="<?php echo esc_attr($link->link_url); ?>" id="link_url" /> <p><?php _e('Example: <code>http://wordpress.org/</code> &#8212; don&#8217;t forget the <code>http://</code>'); ?></p> </div> </div> <div id="descriptiondiv" class="stuffbox"> <h3><label for="link_description"><?php _e('Description') ?></label></h3> <div class="inside"> <input type="text" name="link_description" size="30" tabindex="1" value="<?php echo isset($link->link_description) ? esc_attr($link->link_description) : ''; ?>" id="link_description" /> <p><?php _e('This will be shown when someone hovers over the link in the blogroll, or optionally below the link.'); ?></p> </div> </div> </div><!-- /post-body-content --> <div id="postbox-container-1" class="postbox-container"> <?php do_action('submitlink_box'); $side_meta_boxes = do_meta_boxes( 'link', 'side', $link ); ?> </div> <div id="postbox-container-2" class="postbox-container"> <?php do_meta_boxes(null, 'normal', $link); do_meta_boxes(null, 'advanced', $link); ?> </div> <?php if ( $link_id ) : ?> <input type="hidden" name="action" value="save" /> <input type="hidden" name="link_id" value="<?php echo (int) $link_id; ?>" /> <input type="hidden" name="order_by" value="<?php echo esc_attr($order_by); ?>" /> <input type="hidden" name="cat_id" value="<?php echo (int) $cat_id ?>" /> <?php else: ?> <input type="hidden" name="action" value="add" /> <?php endif; ?> </div> </div> </form> </div>
01happy-blog
trunk/myblog/wp-admin/edit-link-form.php
PHP
oos
5,598
<?php /** * Link Management Administration Screen. * * @package WordPress * @subpackage Administration */ /** Load WordPress Administration Bootstrap */ require_once ('admin.php'); if ( ! current_user_can( 'manage_links' ) ) wp_die( __( 'You do not have sufficient permissions to edit the links for this site.' ) ); $wp_list_table = _get_list_table('WP_Links_List_Table'); // Handle bulk deletes $doaction = $wp_list_table->current_action(); if ( $doaction && isset( $_REQUEST['linkcheck'] ) ) { check_admin_referer( 'bulk-bookmarks' ); if ( 'delete' == $doaction ) { $bulklinks = (array) $_REQUEST['linkcheck']; foreach ( $bulklinks as $link_id ) { $link_id = (int) $link_id; wp_delete_link( $link_id ); } wp_redirect( add_query_arg('deleted', count( $bulklinks ), admin_url( 'link-manager.php' ) ) ); exit; } } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) ); exit; } $wp_list_table->prepare_items(); $title = __('Links'); $this_file = $parent_file = 'link-manager.php'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . sprintf(__('You can add links here to be displayed on your site, usually using <a href="%s">Widgets</a>. By default, links to several sites in the WordPress community are included as examples.'), 'widgets.php') . '</p>' . '<p>' . __('Links may be separated into Link Categories; these are different than the categories used on your posts.') . '</p>' . '<p>' . __('You can customize the display of this screen using the Screen Options tab and/or the dropdown filters above the links table.') . '</p>' ) ); get_current_screen()->add_help_tab( array( 'id' => 'deleting-links', 'title' => __('Deleting Links'), 'content' => '<p>' . __('If you delete a link, it will be removed permanently, as Links do not have a Trash function yet.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Links_Screen" target="_blank">Documentation on Managing Links</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); include_once ('./admin-header.php'); if ( ! current_user_can('manage_links') ) wp_die(__("You do not have sufficient permissions to edit the links for this site.")); ?> <div class="wrap nosubsub"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?> <a href="link-add.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'link'); ?></a> <?php if ( !empty($_REQUEST['s']) ) printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?> </h2> <?php if ( isset($_REQUEST['deleted']) ) { echo '<div id="message" class="updated"><p>'; $deleted = (int) $_REQUEST['deleted']; printf(_n('%s link deleted.', '%s links deleted', $deleted), $deleted); echo '</p></div>'; $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']); } ?> <form id="posts-filter" action="" method="get"> <?php $wp_list_table->search_box( __( 'Search Links' ), 'link' ); ?> <?php $wp_list_table->display(); ?> <div id="ajax-response"></div> </form> </div> <?php include('./admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/link-manager.php
PHP
oos
3,434
<?php /** * The custom background script. * * @package WordPress * @subpackage Administration */ /** * The custom background class. * * @since 3.0.0 * @package WordPress * @subpackage Administration */ class Custom_Background { /** * Callback for administration header. * * @var callback * @since 3.0.0 * @access private */ var $admin_header_callback; /** * Callback for header div. * * @var callback * @since 3.0.0 * @access private */ var $admin_image_div_callback; /** * Holds the page menu hook. * * @var string * @since 3.0.0 * @access private */ var $page = ''; /** * Constructor - Register administration header callback. * * @since 3.0.0 * @param callback $admin_header_callback * @param callback $admin_image_div_callback Optional custom image div output callback. * @return Custom_Background */ function __construct($admin_header_callback = '', $admin_image_div_callback = '') { $this->admin_header_callback = $admin_header_callback; $this->admin_image_div_callback = $admin_image_div_callback; add_action( 'admin_menu', array( $this, 'init' ) ); add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) ); } /** * Set up the hooks for the Custom Background admin page. * * @since 3.0.0 */ function init() { if ( ! current_user_can('edit_theme_options') ) return; $this->page = $page = add_theme_page(__('Background'), __('Background'), 'edit_theme_options', 'custom-background', array(&$this, 'admin_page')); add_action("load-$page", array(&$this, 'admin_load')); add_action("load-$page", array(&$this, 'take_action'), 49); add_action("load-$page", array(&$this, 'handle_upload'), 49); if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) { add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); add_filter( 'media_upload_mime_type_links', '__return_empty_array' ); } if ( $this->admin_header_callback ) add_action("admin_head-$page", $this->admin_header_callback, 51); } /** * Set up the enqueue for the CSS & JavaScript files. * * @since 3.0.0 */ function admin_load() { get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __( 'You can customize the look of your site without touching any of your theme&#8217;s code by using a custom background. Your background can be an image or a color.' ) . '</p>' . '<p>' . __( 'To use a background image, simply upload it, then choose your display options below. You can display a single instance of your image, or tile it to fill the screen. You can have your background fixed in place, so your site content moves on top of it, or you can have it scroll with your site.' ) . '</p>' . '<p>' . __( 'You can also choose a background color. If you know the hexadecimal code for the color you want, enter it in the Background Color field. If not, click on the Select a Color link, and a color picker will allow you to choose the exact shade you want.' ) . '</p>' . '<p>' . __( 'Don&#8217;t forget to click on the Save Changes button when you are finished.' ) . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . '<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Background_Screen" target="_blank">Documentation on Custom Background</a>' ) . '</p>' . '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' ); add_thickbox(); wp_enqueue_script('media-upload'); wp_enqueue_script('custom-background'); wp_enqueue_style('farbtastic'); } /** * Execute custom background modification. * * @since 3.0.0 */ function take_action() { if ( empty($_POST) ) return; if ( isset($_POST['reset-background']) ) { check_admin_referer('custom-background-reset', '_wpnonce-custom-background-reset'); remove_theme_mod('background_image'); remove_theme_mod('background_image_thumb'); $this->updated = true; return; } if ( isset($_POST['remove-background']) ) { // @TODO: Uploaded files are not removed here. check_admin_referer('custom-background-remove', '_wpnonce-custom-background-remove'); set_theme_mod('background_image', ''); set_theme_mod('background_image_thumb', ''); $this->updated = true; wp_safe_redirect( $_POST['_wp_http_referer'] ); return; } if ( isset($_POST['background-repeat']) ) { check_admin_referer('custom-background'); if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat', 'repeat-x', 'repeat-y')) ) $repeat = $_POST['background-repeat']; else $repeat = 'repeat'; set_theme_mod('background_repeat', $repeat); } if ( isset($_POST['background-position-x']) ) { check_admin_referer('custom-background'); if ( in_array($_POST['background-position-x'], array('center', 'right', 'left')) ) $position = $_POST['background-position-x']; else $position = 'left'; set_theme_mod('background_position_x', $position); } if ( isset($_POST['background-attachment']) ) { check_admin_referer('custom-background'); if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) ) $attachment = $_POST['background-attachment']; else $attachment = 'fixed'; set_theme_mod('background_attachment', $attachment); } if ( isset($_POST['background-color']) ) { check_admin_referer('custom-background'); $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); if ( strlen($color) == 6 || strlen($color) == 3 ) set_theme_mod('background_color', $color); else set_theme_mod('background_color', ''); } $this->updated = true; } /** * Display the custom background page. * * @since 3.0.0 */ function admin_page() { ?> <div class="wrap" id="custom-background"> <?php screen_icon(); ?> <h2><?php _e('Custom Background'); ?></h2> <?php if ( !empty($this->updated) ) { ?> <div id="message" class="updated"> <p><?php printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p> </div> <?php } if ( $this->admin_image_div_callback ) { call_user_func($this->admin_image_div_callback); } else { ?> <h3><?php _e('Background Image'); ?></h3> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row"><?php _e('Preview'); ?></th> <td> <?php $background_styles = ''; if ( $bgcolor = get_background_color() ) $background_styles .= 'background-color: #' . $bgcolor . ';'; if ( get_background_image() ) { // background-image URL must be single quote, see below $background_styles .= ' background-image: url(\'' . set_url_scheme( get_theme_mod( 'background_image_thumb', get_background_image() ) ) . '\');' . ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';' . ' background-position: top ' . get_theme_mod('background_position_x', 'left'); } ?> <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?> <?php if ( get_background_image() ) { ?> <img class="custom-background-image" src="<?php echo set_url_scheme( get_theme_mod( 'background_image_thumb', get_background_image() ) ); ?>" style="visibility:hidden;" alt="" /><br /> <img class="custom-background-image" src="<?php echo set_url_scheme( get_theme_mod( 'background_image_thumb', get_background_image() ) ); ?>" style="visibility:hidden;" alt="" /> <?php } ?> </div> <?php } ?> </td> </tr> <?php if ( get_background_image() ) : ?> <tr valign="top"> <th scope="row"><?php _e('Remove Image'); ?></th> <td> <form method="post" action=""> <?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?> <?php submit_button( __( 'Remove Background Image' ), 'button', 'remove-background', false ); ?><br/> <?php _e('This will remove the background image. You will not be able to restore any customizations.') ?> </form> </td> </tr> <?php endif; ?> <?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?> <?php if ( $default_image && get_background_image() != $default_image ) : ?> <tr valign="top"> <th scope="row"><?php _e('Restore Original Image'); ?></th> <td> <form method="post" action=""> <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?> <?php submit_button( __( 'Restore Original Image' ), 'button', 'reset-background', false ); ?><br/> <?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?> </form> </td> </tr> <?php endif; ?> <tr valign="top"> <th scope="row"><?php _e('Select Image'); ?></th> <td><form enctype="multipart/form-data" id="upload-form" method="post" action=""> <p> <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> <input type="file" id="upload" name="import" /> <input type="hidden" name="action" value="save" /> <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?> <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> </p> <?php $image_library_url = get_upload_iframe_src( 'image', null, 'library' ); $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); $image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url ); ?> <p> <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> <a id="choose-from-library-link" class="button thickbox" href="<?php echo esc_url( $image_library_url ); ?>"><?php _e( 'Choose Image' ); ?></a> </p> </form> </td> </tr> </tbody> </table> <h3><?php _e('Display Options') ?></h3> <form method="post" action=""> <table class="form-table"> <tbody> <?php if ( get_background_image() ) : ?> <tr valign="top"> <th scope="row"><?php _e( 'Position' ); ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend> <label> <input name="background-position-x" type="radio" value="left"<?php checked('left', get_theme_mod('background_position_x', 'left')); ?> /> <?php _e('Left') ?> </label> <label> <input name="background-position-x" type="radio" value="center"<?php checked('center', get_theme_mod('background_position_x', 'left')); ?> /> <?php _e('Center') ?> </label> <label> <input name="background-position-x" type="radio" value="right"<?php checked('right', get_theme_mod('background_position_x', 'left')); ?> /> <?php _e('Right') ?> </label> </fieldset></td> </tr> <tr valign="top"> <th scope="row"><?php _e( 'Repeat' ); ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend> <label><input type="radio" name="background-repeat" value="no-repeat"<?php checked('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('No Repeat'); ?></label> <label><input type="radio" name="background-repeat" value="repeat"<?php checked('repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile'); ?></label> <label><input type="radio" name="background-repeat" value="repeat-x"<?php checked('repeat-x', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile Horizontally'); ?></label> <label><input type="radio" name="background-repeat" value="repeat-y"<?php checked('repeat-y', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile Vertically'); ?></label> </fieldset></td> </tr> <tr valign="top"> <th scope="row"><?php _e( 'Attachment' ); ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend> <label> <input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment', 'scroll')); ?> /> <?php _e('Scroll') ?> </label> <label> <input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'scroll')); ?> /> <?php _e('Fixed') ?> </label> </fieldset></td> </tr> <?php endif; // get_background_image() ?> <tr valign="top"> <th scope="row"><?php _e( 'Background Color' ); ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> <?php $show_clear = get_theme_mod('background_color') ? '' : ' style="display:none"'; ?> <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr(get_background_color()) ?>" /> <a class="hide-if-no-js" href="#" id="pickcolor"><?php _e('Select a Color'); ?></a> <span<?php echo $show_clear; ?> class="hide-if-no-js" id="clearcolor"> (<a href="#"><?php current_theme_supports( 'custom-background', 'default-color' ) ? _e( 'Default' ) : _e( 'Clear' ); ?></a>)</span> <input type="hidden" id="defaultcolor" value="<?php if ( current_theme_supports( 'custom-background', 'default-color' ) ) echo '#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ); ?>" /> <div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> </fieldset></td> </tr> </tbody> </table> <?php wp_nonce_field('custom-background'); ?> <?php submit_button( null, 'primary', 'save-background-options' ); ?> </form> </div> <?php } /** * Handle an Image upload for the background image. * * @since 3.0.0 */ function handle_upload() { if ( empty($_FILES) ) return; check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload'); $overrides = array('test_form' => false); $file = wp_handle_upload($_FILES['import'], $overrides); if ( isset($file['error']) ) wp_die( $file['error'] ); $url = $file['url']; $type = $file['type']; $file = $file['file']; $filename = basename($file); // Construct the object array $object = array( 'post_title' => $filename, 'post_content' => $url, 'post_mime_type' => $type, 'guid' => $url, 'context' => 'custom-background' ); // Save the data $id = wp_insert_attachment($object, $file); // Add the meta-data wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); update_post_meta( $id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); set_theme_mod('background_image', esc_url_raw($url)); $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); set_theme_mod('background_image_thumb', esc_url_raw( $thumbnail[0] ) ); do_action('wp_create_file_in_uploads', $file, $id); // For replication $this->updated = true; } /** * Replace default attachment actions with "Set as background" link. * * @since 3.4.0 */ function attachment_fields_to_edit( $form_fields, $post ) { $form_fields = array( 'image-size' => $form_fields['image-size'] ); $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-attachment-id="' . $post->ID . '" class="wp-set-background">' . __( 'Set as background' ) . '</a></td></tr>' ); $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); return $form_fields; } /** * Leave only "Media Library" tab in the uploader window. * * @since 3.4.0 */ function filter_upload_tabs() { return array( 'library' => __('Media Library') ); } public function wp_set_background_image() { if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; $attachment_id = absint($_POST['attachment_id']); $sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) )); $size = 'thumbnail'; if ( in_array( $_POST['size'], $sizes ) ) $size = esc_attr( $_POST['size'] ); update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); $url = wp_get_attachment_image_src( $attachment_id, $size ); $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); set_theme_mod( 'background_image', esc_url_raw( $url[0] ) ); set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) ); exit; } }
01happy-blog
trunk/myblog/wp-admin/custom-background.php
PHP
oos
16,404
<?php /** * Customize Controls * * @package WordPress * @subpackage Customize * @since 3.4.0 */ define( 'IFRAME_REQUEST', true ); require_once( './admin.php' ); if ( ! current_user_can( 'edit_theme_options' ) ) wp_die( __( 'Cheatin&#8217; uh?' ) ); wp_reset_vars( array( 'url', 'return' ) ); $url = urldecode( $url ); $url = wp_validate_redirect( $url, home_url( '/' ) ); if ( $return ) $return = wp_validate_redirect( urldecode( $return ) ); if ( ! $return ) $return = $url; global $wp_scripts, $wp_customize; $registered = $wp_scripts->registered; $wp_scripts = new WP_Scripts; $wp_scripts->registered = $registered; add_action( 'customize_controls_print_scripts', 'print_head_scripts', 20 ); add_action( 'customize_controls_print_footer_scripts', '_wp_footer_scripts' ); add_action( 'customize_controls_print_styles', 'print_admin_styles', 20 ); do_action( 'customize_controls_init' ); wp_enqueue_script( 'customize-controls' ); wp_enqueue_style( 'customize-controls' ); do_action( 'customize_controls_enqueue_scripts' ); // Let's roll. @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); wp_user_settings(); _wp_admin_html_begin(); $body_class = ''; if ( wp_is_mobile() ) : $body_class .= ' mobile'; ?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2"><?php endif; $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] ); if ( $is_ios ) $body_class .= ' ios'; $admin_title = sprintf( __( '%1$s &#8212; WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) ); ?><title><?php echo $admin_title; ?></title><?php do_action( 'customize_controls_print_styles' ); do_action( 'customize_controls_print_scripts' ); ?> </head> <body class="<?php echo esc_attr( $body_class ); ?>"> <div class="wp-full-overlay expanded"> <form id="customize-controls" class="wrap wp-full-overlay-sidebar"> <div id="customize-header-actions" class="wp-full-overlay-header"> <?php $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' ); submit_button( $save_text, 'primary', 'save', false ); ?> <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" /> <a class="back button" href="<?php echo esc_url( $return ? $return : admin_url( 'themes.php' ) ); ?>"> <?php _e( 'Cancel' ); ?> </a> </div> <?php $screenshot = $wp_customize->theme()->get_screenshot(); $cannot_expand = ! ( $screenshot || $wp_customize->theme()->get('Description') ); ?> <div class="wp-full-overlay-sidebar-content"> <div id="customize-info" class="customize-section<?php if ( $cannot_expand ) echo ' cannot-expand'; ?>"> <div class="customize-section-title"> <span class="preview-notice"><?php /* translators: %s is the theme name in the Customize/Live Preview pane */ echo sprintf( __( 'You are previewing %s' ), '<strong class="theme-name">' . $wp_customize->theme()->display('Name') . '</strong>' ); ?></span> </div> <?php if ( ! $cannot_expand ) : ?> <div class="customize-section-content"> <?php if ( $screenshot ) : ?> <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" /> <?php endif; ?> <?php if ( $wp_customize->theme()->get('Description') ): ?> <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div> <?php endif; ?> </div> <?php endif; ?> </div> <div id="customize-theme-controls"><ul> <?php foreach ( $wp_customize->sections() as $section ) $section->maybe_render(); ?> </ul></div> </div> <div id="customize-footer-actions" class="wp-full-overlay-footer"> <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>"> <span class="collapse-sidebar-arrow"></span> <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span> </a> </div> </form> <div id="customize-preview" class="wp-full-overlay-main"></div> <?php do_action( 'customize_controls_print_footer_scripts' ); // If the frontend and the admin are served from the same domain, load the // preview over ssl if the customizer is being loaded over ssl. This avoids // insecure content warnings. This is not attempted if the admin and frontend // are on different domains to avoid the case where the frontend doesn't have // ssl certs. Domain mapping plugins can allow other urls in these conditions // using the customize_allowed_urls filter. $allowed_urls = array( home_url('/') ); $admin_origin = parse_url( admin_url() ); $home_origin = parse_url( home_url() ); $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); if ( is_ssl() && ! $cross_domain ) $allowed_urls[] = home_url( '/', 'https' ); $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) ); $fallback_url = add_query_arg( array( 'preview' => 1, 'template' => $wp_customize->get_template(), 'stylesheet' => $wp_customize->get_stylesheet(), 'preview_iframe' => true, 'TB_iframe' => 'true' ), home_url( '/' ) ); $login_url = add_query_arg( array( 'interim-login' => 1, 'customize-login' => 1 ), wp_login_url() ); $settings = array( 'theme' => array( 'stylesheet' => $wp_customize->get_stylesheet(), 'active' => $wp_customize->is_theme_active(), ), 'url' => array( 'preview' => esc_url( $url ? $url : home_url( '/' ) ), 'parent' => esc_url( admin_url() ), 'activated' => admin_url( 'themes.php?activated=true&previewed' ), 'ajax' => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ), 'allowed' => array_map( 'esc_url', $allowed_urls ), 'isCrossDomain' => $cross_domain, 'fallback' => $fallback_url, 'home' => esc_url( home_url( '/' ) ), 'login' => $login_url, ), 'browser' => array( 'mobile' => wp_is_mobile(), 'ios' => $is_ios, ), 'settings' => array(), 'controls' => array(), 'nonce' => array( 'save' => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ), 'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() ) ), ); foreach ( $wp_customize->settings() as $id => $setting ) { $settings['settings'][ $id ] = array( 'value' => $setting->js_value(), 'transport' => $setting->transport, ); } foreach ( $wp_customize->controls() as $id => $control ) { $control->to_json(); $settings['controls'][ $id ] = $control->json; } ?> <script type="text/javascript"> var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>; </script> </div> </body> </html>
01happy-blog
trunk/myblog/wp-admin/customize.php
PHP
oos
6,920
<?php /** * Edit Site Info Administration Screen * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have sufficient permissions to edit this site.' ) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.') . '</p>' . '<p>' . __('<strong>Info</strong> - The domain and path are rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.') . '</p>' . '<p>' . __('<strong>Users</strong> - This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.') . '</p>' . '<p>' . sprintf( __('<strong>Themes</strong> - This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' . '<p>' . __('<strong>Settings</strong> - This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; if ( ! $id ) wp_die( __('Invalid site ID.') ); $details = get_blog_details( $id ); if ( !can_edit_network( $details->site_id ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $is_main_site = is_main_site( $id ); if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) { check_admin_referer( 'edit-site' ); switch_to_blog( $id ); if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) { $blog_address = get_blogaddress_by_domain( $_POST['blog']['domain'], $_POST['blog']['path'] ); if ( get_option( 'siteurl' ) != $blog_address ) update_option( 'siteurl', $blog_address ); if ( get_option( 'home' ) != $blog_address ) update_option( 'home', $blog_address ); } // rewrite rules can't be flushed during switch to blog delete_option( 'rewrite_rules' ); // update blogs table $blog_data = stripslashes_deep( $_POST['blog'] ); $existing_details = get_blog_details( $id, false ); $blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' ); foreach ( $blog_data_checkboxes as $c ) { if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) $blog_data[ $c ] = $existing_details->$c; else $blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0; } update_blog_details( $id, $blog_data ); restore_current_blog(); wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-info.php') ); exit; } if ( isset($_GET['update']) ) { $messages = array(); if ( 'updated' == $_GET['update'] ) $messages[] = __('Site info updated.'); } $site_url_no_http = preg_replace( '#^http(s)?://#', '', get_blogaddress_by_id( $id ) ); $title_site_url_linked = sprintf( __('Edit Site: <a href="%1$s">%2$s</a>'), get_blogaddress_by_id( $id ), $site_url_no_http ); $title = sprintf( __('Edit Site: %s'), $site_url_no_http ); $parent_file = 'sites.php'; $submenu_file = 'sites.php'; require('../admin-header.php'); ?> <div class="wrap"> <?php screen_icon('ms-admin'); ?> <h2 id="edit-site"><?php echo $title_site_url_linked ?></h2> <h3 class="nav-tab-wrapper"> <?php $tabs = array( 'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ), 'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ), 'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ), 'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ), ); foreach ( $tabs as $tab_id => $tab ) { $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : ''; echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>'; } ?> </h3> <?php if ( ! empty( $messages ) ) { foreach ( $messages as $msg ) echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; } ?> <form method="post" action="site-info.php?action=update-site"> <?php wp_nonce_field( 'edit-site' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> <table class="form-table"> <tr class="form-field form-required"> <th scope="row"><?php _e( 'Domain' ) ?></th> <?php $protocol = is_ssl() ? 'https://' : 'http://'; if ( $is_main_site ) { ?> <td><code><?php echo $protocol; echo esc_attr( $details->domain ) ?></code></td> <?php } else { ?> <td><?php echo $protocol; ?><input name="blog[domain]" type="text" id="domain" value="<?php echo esc_attr( $details->domain ) ?>" size="33" /></td> <?php } ?> </tr> <tr class="form-field form-required"> <th scope="row"><?php _e( 'Path' ) ?></th> <?php if ( $is_main_site ) { ?> <td><code><?php echo esc_attr( $details->path ) ?></code></td> <?php } else { ?> <td><input name="blog[path]" type="text" id="path" value="<?php echo esc_attr( $details->path ) ?>" size="40" style='margin-bottom:5px;' /> <br /><input type="checkbox" style="width:20px;" name="update_home_url" value="update" <?php if ( get_blog_option( $id, 'siteurl' ) == untrailingslashit( get_blogaddress_by_id ($id ) ) || get_blog_option( $id, 'home' ) == untrailingslashit( get_blogaddress_by_id( $id ) ) ) echo 'checked="checked"'; ?> /> <?php _e( 'Update <code>siteurl</code> and <code>home</code> as well.' ); ?></td> <?php } ?> </tr> <tr class="form-field"> <th scope="row"><?php _ex( 'Registered', 'site' ) ?></th> <td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" size="40" /></td> </tr> <tr class="form-field"> <th scope="row"><?php _e( 'Last Updated' ); ?></th> <td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ) ?>" size="40" /></td> </tr> <?php $attribute_fields = array( 'public' => __( 'Public' ) ); if ( ! $is_main_site ) { $attribute_fields['archived'] = __( 'Archived' ); $attribute_fields['spam'] = _x( 'Spam', 'site' ); $attribute_fields['deleted'] = __( 'Deleted' ); } $attribute_fields['mature'] = __( 'Mature' ); ?> <tr> <th scope="row"><?php _e( 'Attributes' ); ?></th> <td> <?php foreach ( $attribute_fields as $field_key => $field_label ) : ?> <label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); disabled( ! in_array( $details->$field_key, array( 0, 1 ) ) ); ?> /> <?php echo $field_label; ?></label><br/> <?php endforeach; ?> </td> </tr> </table> <?php submit_button(); ?> </form> </div> <?php require('../admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/network/site-info.php
PHP
oos
8,029
<?php /** * Install plugin network administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ if ( isset( $_GET['tab'] ) && ( 'plugin-information' == $_GET['tab'] ) ) define( 'IFRAME_REQUEST', true ); /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../plugin-install.php' );
01happy-blog
trunk/myblog/wp-admin/network/plugin-install.php
PHP
oos
431
<?php /** * Network About administration panel. * * @package WordPress * @subpackage Multisite * @since 3.4.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../about.php' );
01happy-blog
trunk/myblog/wp-admin/network/about.php
PHP
oos
304
<?php /** * Update/Install Plugin/Theme network administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ if ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ) ) ) define( 'IFRAME_REQUEST', true ); /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../update.php' );
01happy-blog
trunk/myblog/wp-admin/network/update.php
PHP
oos
500
<?php /** * Action handler for Multisite administration panels. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( empty( $_GET['action'] ) ) { wp_redirect( network_admin_url() ); exit; } do_action( 'wpmuadminedit' , '' ); // Let plugins use us as a post handler easily do_action( 'network_admin_edit_' . $_GET['action'] ); wp_redirect( network_admin_url() ); exit();
01happy-blog
trunk/myblog/wp-admin/network/edit.php
PHP
oos
557
<?php /** * Edit Site Settings Administration Screen * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have sufficient permissions to edit this site.' ) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.') . '</p>' . '<p>' . __('<strong>Info</strong> - The domain and path are rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.') . '</p>' . '<p>' . __('<strong>Users</strong> - This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.') . '</p>' . '<p>' . sprintf( __('<strong>Themes</strong> - This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' . '<p>' . __('<strong>Settings</strong> - This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; if ( ! $id ) wp_die( __('Invalid site ID.') ); $details = get_blog_details( $id ); if ( !can_edit_network( $details->site_id ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $is_main_site = is_main_site( $id ); if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] && is_array( $_POST['option'] ) ) { check_admin_referer( 'edit-site' ); switch_to_blog( $id ); $c = 1; $count = count( $_POST['option'] ); $skip_options = array( 'allowedthemes' ); // Don't update these options since they are handled elsewhere in the form. foreach ( (array) $_POST['option'] as $key => $val ) { if ( $key === 0 || is_array( $val ) || in_array($key, $skip_options) ) continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options if ( $c == $count ) update_option( $key, stripslashes( $val ) ); else update_option( $key, stripslashes( $val ), false ); // no need to refresh blog details yet $c++; } do_action( 'wpmu_update_blog_options' ); restore_current_blog(); wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-settings.php') ); exit; } if ( isset($_GET['update']) ) { $messages = array(); if ( 'updated' == $_GET['update'] ) $messages[] = __('Site options updated.'); } $site_url_no_http = preg_replace( '#^http(s)?://#', '', get_blogaddress_by_id( $id ) ); $title_site_url_linked = sprintf( __('Edit Site: <a href="%1$s">%2$s</a>'), get_blogaddress_by_id( $id ), $site_url_no_http ); $title = sprintf( __('Edit Site: %s'), $site_url_no_http ); $parent_file = 'sites.php'; $submenu_file = 'sites.php'; require('../admin-header.php'); ?> <div class="wrap"> <?php screen_icon('ms-admin'); ?> <h2 id="edit-site"><?php echo $title_site_url_linked ?></h2> <h3 class="nav-tab-wrapper"> <?php $tabs = array( 'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ), 'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ), 'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ), 'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ), ); foreach ( $tabs as $tab_id => $tab ) { $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : ''; echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>'; } ?> </h3> <?php if ( ! empty( $messages ) ) { foreach ( $messages as $msg ) echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; } ?> <form method="post" action="site-settings.php?action=update-site"> <?php wp_nonce_field( 'edit-site' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> <table class="form-table"> <?php $blog_prefix = $wpdb->get_blog_prefix( $id ); $options = $wpdb->get_results( "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE '\_%' AND option_name NOT LIKE '%user_roles'" ); foreach ( $options as $option ) { if ( $option->option_name == 'default_role' ) $editblog_default_role = $option->option_value; $disabled = false; $class = 'all-options'; if ( is_serialized( $option->option_value ) ) { if ( is_serialized_string( $option->option_value ) ) { $option->option_value = esc_html( maybe_unserialize( $option->option_value ), 'single' ); } else { $option->option_value = 'SERIALIZED DATA'; $disabled = true; $class = 'all-options disabled'; } } if ( strpos( $option->option_value, "\n" ) !== false ) { ?> <tr class="form-field"> <th scope="row"><?php echo ucwords( str_replace( "_", " ", $option->option_name ) ) ?></th> <td><textarea class="<?php echo $class; ?>" rows="5" cols="40" name="option[<?php echo esc_attr( $option->option_name ) ?>]" id="<?php echo esc_attr( $option->option_name ) ?>"<?php disabled( $disabled ) ?>><?php echo esc_textarea( $option->option_value ) ?></textarea></td> </tr> <?php } else { ?> <tr class="form-field"> <th scope="row"><?php echo esc_html( ucwords( str_replace( "_", " ", $option->option_name ) ) ); ?></th> <?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ) ) ) { ?> <td><code><?php echo esc_html( $option->option_value ) ?></code></td> <?php } else { ?> <td><input class="<?php echo $class; ?>" name="option[<?php echo esc_attr( $option->option_name ) ?>]" type="text" id="<?php echo esc_attr( $option->option_name ) ?>" value="<?php echo esc_attr( $option->option_value ) ?>" size="40" <?php disabled( $disabled ) ?> /></td> <?php } ?> </tr> <?php } } // End foreach do_action( 'wpmueditblogaction', $id ); ?> </table> <?php submit_button(); ?> </form> </div> <?php require('../admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/network/site-settings.php
PHP
oos
7,264
<?php /** * Multisite sites administration panel. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $wp_list_table = _get_list_table('WP_MS_Sites_List_Table'); $pagenum = $wp_list_table->get_pagenum(); $title = __( 'Sites' ); $parent_file = 'sites.php'; add_screen_option( 'per_page', array('label' => _x( 'Sites', 'sites per page (screen options)' )) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('Add New takes you to the Add New Site screen. You can search for a site by Name, ID number, or IP address. Screen Options allows you to choose how many sites to display on one page.') . '</p>' . '<p>' . __('This is the main table of all sites on this network. Switch between list and excerpt views by using the icons above the right side of the table.') . '</p>' . '<p>' . __('Hovering over each site reveals seven options (three for the primary site):') . '</p>' . '<ul><li>' . __('An Edit link to a separate Edit Site screen.') . '</li>' . '<li>' . __('Dashboard leads to the Dashboard for that site.') . '</li>' . '<li>' . __('Deactivate, Archive, and Spam which lead to confirmation screens. These actions can be reversed later.') . '</li>' . '<li>' . __('Delete which is a permanent action after the confirmation screens.') . '</li>' . '<li>' . __('Visit to go to the frontend site live.') . '</li></ul>' . '<p>' . __('The site ID is used internally, and is not shown on the front end of the site or to users/viewers.') . '</p>' . '<p>' . __('Clicking on bold headings can re-sort this table.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; if ( isset( $_GET['action'] ) ) { do_action( 'wpmuadminedit' , '' ); switch ( $_GET['action'] ) { case 'updateblog': // No longer used. break; case 'deleteblog': check_admin_referer('deleteblog'); if ( ! ( current_user_can( 'manage_sites' ) && current_user_can( 'delete_sites' ) ) ) wp_die( __( 'You do not have permission to access this page.' ) ); if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) { wpmu_delete_blog( $id, true ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) ); } else { wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'not_deleted' ), wp_get_referer() ) ); } exit(); break; case 'allblogs': if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) { check_admin_referer( 'bulk-sites' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2']; $blogfunction = ''; foreach ( (array) $_POST['allblogs'] as $key => $val ) { if ( $val != '0' && $val != $current_site->blog_id ) { switch ( $doaction ) { case 'delete': if ( ! current_user_can( 'delete_site', $val ) ) wp_die( __( 'You are not allowed to delete the site.' ) ); $blogfunction = 'all_delete'; wpmu_delete_blog( $val, true ); break; case 'spam': $blogfunction = 'all_spam'; update_blog_status( $val, 'spam', '1' ); set_time_limit( 60 ); break; case 'notspam': $blogfunction = 'all_notspam'; update_blog_status( $val, 'spam', '0' ); set_time_limit( 60 ); break; } } else { wp_die( __( 'You are not allowed to change the current site.' ) ); } } wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $blogfunction ), wp_get_referer() ) ); } else { wp_redirect( network_admin_url( 'sites.php' ) ); } exit(); break; case 'archiveblog': check_admin_referer( 'archiveblog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); update_blog_status( $id, 'archived', '1' ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'archive' ), wp_get_referer() ) ); exit(); break; case 'unarchiveblog': check_admin_referer( 'unarchiveblog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); update_blog_status( $id, 'archived', '0' ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unarchive' ), wp_get_referer() ) ); exit(); break; case 'activateblog': check_admin_referer( 'activateblog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); update_blog_status( $id, 'deleted', '0' ); do_action( 'activate_blog', $id ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'activate' ), wp_get_referer() ) ); exit(); break; case 'deactivateblog': check_admin_referer( 'deactivateblog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); do_action( 'deactivate_blog', $id ); update_blog_status( $id, 'deleted', '1' ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'deactivate' ), wp_get_referer() ) ); exit(); break; case 'unspamblog': check_admin_referer( 'unspamblog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); update_blog_status( $id, 'spam', '0' ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unspam' ), wp_get_referer() ) ); exit(); break; case 'spamblog': check_admin_referer( 'spamblog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); update_blog_status( $id, 'spam', '1' ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'spam' ), wp_get_referer() ) ); exit(); break; case 'unmatureblog': check_admin_referer( 'unmatureblog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); update_blog_status( $id, 'mature', '0' ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unmature' ), wp_get_referer() ) ); exit(); break; case 'matureblog': check_admin_referer( 'matureblog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); update_blog_status( $id, 'mature', '1' ); wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'mature' ), wp_get_referer() ) ); exit(); break; // Common case 'confirm': check_admin_referer( 'confirm' ); if ( !headers_sent() ) { nocache_headers(); header( 'Content-Type: text/html; charset=utf-8' ); } if ( $current_site->blog_id == $id ) wp_die( __( 'You are not allowed to change the current site.' ) ); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head> <title><?php _e( 'WordPress &rsaquo; Confirm your action' ); ?></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php wp_admin_css( 'install', true ); wp_admin_css( 'ie', true ); ?> </head> <body> <h1 id="logo"><img alt="WordPress" src="<?php echo esc_attr( admin_url( 'images/wordpress-logo.png?ver=20120216' ) ); ?>" /></h1> <form action="sites.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post"> <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" /> <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" /> <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?> <p><?php echo esc_html( stripslashes( $_GET['msg'] ) ); ?></p> <?php submit_button( __('Confirm'), 'button' ); ?> </form> </body> </html> <?php exit(); break; } } $msg = ''; if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) { switch ( $_REQUEST['action'] ) { case 'all_notspam': $msg = __( 'Sites removed from spam.' ); break; case 'all_spam': $msg = __( 'Sites marked as spam.' ); break; case 'all_delete': $msg = __( 'Sites deleted.' ); break; case 'delete': $msg = __( 'Site deleted.' ); break; case 'not_deleted': $msg = __( 'You do not have permission to delete that site.' ); break; case 'archive': $msg = __( 'Site archived.' ); break; case 'unarchive': $msg = __( 'Site unarchived.' ); break; case 'activate': $msg = __( 'Site activated.' ); break; case 'deactivate': $msg = __( 'Site deactivated.' ); break; case 'unspam': $msg = __( 'Site removed from spam.' ); break; case 'spam': $msg = __( 'Site marked as spam.' ); break; default: $msg = apply_filters( 'network_sites_updated_message_' . $_REQUEST['action'] , __( 'Settings saved.' ) ); break; } if ( $msg ) $msg = '<div class="updated" id="message"><p>' . $msg . '</p></div>'; } $wp_list_table->prepare_items(); require_once( '../admin-header.php' ); ?> <div class="wrap"> <?php screen_icon('ms-admin'); ?> <h2><?php _e('Sites') ?> <?php echo $msg; ?> <?php if ( current_user_can( 'create_sites') ) : ?> <a href="<?php echo network_admin_url('site-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'site' ); ?></a> <?php endif; ?> <?php if ( isset( $_REQUEST['s'] ) && $_REQUEST['s'] ) { printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) ); } ?> </h2> <form action="" method="get" id="ms-search"> <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?> <input type="hidden" name="action" value="blogs" /> </form> <form id="form-site-list" action="sites.php?action=allblogs" method="post"> <?php $wp_list_table->display(); ?> </form> </div> <?php require_once( '../admin-footer.php' ); ?>
01happy-blog
trunk/myblog/wp-admin/network/sites.php
PHP
oos
10,962
<?php /** * Build Network Administration Menu. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /* translators: Network menu item */ $menu[2] = array(__('Dashboard'), 'manage_network', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'div'); $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' ); /* translators: Sites menu item */ $menu[5] = array(__('Sites'), 'manage_sites', 'sites.php', '', 'menu-top menu-icon-site', 'menu-site', 'div'); $submenu['sites.php'][5] = array( __('All Sites'), 'manage_sites', 'sites.php' ); $submenu['sites.php'][10] = array( _x('Add New', 'site'), 'create_sites', 'site-new.php' ); $menu[10] = array(__('Users'), 'manage_network_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div'); $submenu['users.php'][5] = array( __('All Users'), 'manage_network_users', 'users.php' ); $submenu['users.php'][10] = array( _x('Add New', 'user'), 'create_users', 'user-new.php' ); $update_data = wp_get_update_data(); if ( $update_data['counts']['themes'] ) { $menu[15] = array(sprintf( __( 'Themes %s' ), "<span class='update-plugins count-{$update_data['counts']['themes']}'><span class='theme-count'>" . number_format_i18n( $update_data['counts']['themes'] ) . "</span></span>" ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); } else { $menu[15] = array( __( 'Themes' ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); } $submenu['themes.php'][5] = array( __('Installed Themes'), 'manage_network_themes', 'themes.php' ); $submenu['themes.php'][10] = array( _x('Add New', 'theme'), 'install_themes', 'theme-install.php' ); $submenu['themes.php'][15] = array( _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php' ); if ( current_user_can( 'update_plugins' ) ) { $menu[20] = array( sprintf( __( 'Plugins %s' ), "<span class='update-plugins count-{$update_data['counts']['plugins']}'><span class='plugin-count'>" . number_format_i18n( $update_data['counts']['plugins'] ) . "</span></span>" ), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div'); } else { $menu[20] = array( __('Plugins'), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' ); } $submenu['plugins.php'][5] = array( __('Installed Plugins'), 'manage_network_plugins', 'plugins.php' ); $submenu['plugins.php'][10] = array( _x('Add New', 'plugin editor'), 'install_plugins', 'plugin-install.php' ); $submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' ); $menu[25] = array(__('Settings'), 'manage_network_options', 'settings.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'div'); if ( defined( 'MULTISITE' ) && defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ) { $submenu['settings.php'][5] = array( __('Network Settings'), 'manage_network_options', 'settings.php' ); $submenu['settings.php'][10] = array( __('Network Setup'), 'manage_network_options', 'setup.php' ); } if ( $update_data['counts']['total'] ) { $menu[30] = array( sprintf( __( 'Updates %s' ), "<span class='update-plugins count-{$update_data['counts']['total']}' title='{$update_data['title']}'><span class='update-count'>" . number_format_i18n($update_data['counts']['total']) . "</span></span>" ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' ); } else { $menu[30] = array( __( 'Updates' ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' ); } unset($update_data); $submenu[ 'upgrade.php' ][10] = array( __( 'Available Updates' ), 'update_core', 'update-core.php' ); $submenu[ 'upgrade.php' ][15] = array( __( 'Update Network' ), 'manage_network', 'upgrade.php' ); $menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator-last' ); require_once(ABSPATH . 'wp-admin/includes/menu.php');
01happy-blog
trunk/myblog/wp-admin/network/menu.php
PHP
oos
4,032
<?php /** * Network Freedoms administration panel. * * @package WordPress * @subpackage Multisite * @since 3.4.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../freedoms.php' );
01happy-blog
trunk/myblog/wp-admin/network/freedoms.php
PHP
oos
310
<?php /** * Edit user network administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../user-edit.php' );
01happy-blog
trunk/myblog/wp-admin/network/user-edit.php
PHP
oos
312
<?php /** * Multisite administration panel. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); /** Load WordPress dashboard API */ require_once( ABSPATH . 'wp-admin/includes/dashboard.php' ); if ( !is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can( 'manage_network' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $title = __( 'Dashboard' ); $parent_file = 'index.php'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('Until WordPress 3.0, running multiple sites required using WordPress MU instead of regular WordPress. In version 3.0, these applications have merged. If you are a former MU user, you should be aware of the following changes:') . '</p>' . '<ul><li>' . __('Site Admin is now Super Admin (we highly encourage you to get yourself a cape!).') . '</li>' . '<li>' . __('Blogs are now called Sites; Site is now called Network.') . '</li></ul>' . '<p>' . __('The Right Now box provides the network administrator with links to the screens to either create a new site or user, or to search existing users and sites. Screens for Sites and Users are also accessible through the left-hand navigation in the Network Admin section.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin" target="_blank">Documentation on the Network Admin</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); wp_dashboard_setup(); wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'plugin-install' ); add_thickbox(); add_screen_option('layout_columns', array('max' => 4, 'default' => 2) ); require_once( '../admin-header.php' ); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <div id="dashboard-widgets-wrap"> <?php wp_dashboard(); ?> <div class="clear"></div> </div><!-- dashboard-widgets-wrap --> </div><!-- wrap --> <?php include( '../admin-footer.php' ); ?>
01happy-blog
trunk/myblog/wp-admin/network/index.php
PHP
oos
2,281
<?php /** * Multisite themes administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); $menu_perms = get_site_option( 'menu_items', array() ); if ( empty( $menu_perms['themes'] ) && ! is_super_admin() ) wp_die( __( 'Cheatin&#8217; uh?' ) ); if ( !current_user_can('manage_network_themes') ) wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) ); $wp_list_table = _get_list_table('WP_MS_Themes_List_Table'); $pagenum = $wp_list_table->get_pagenum(); $action = $wp_list_table->current_action(); $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; // Clean up request URI from temporary args for screen options/paging uri's to work as expected. $temp_args = array( 'enabled', 'disabled', 'deleted', 'error' ); $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] ); $referer = remove_query_arg( $temp_args, wp_get_referer() ); if ( $action ) { $allowed_themes = get_site_option( 'allowedthemes' ); switch ( $action ) { case 'enable': check_admin_referer('enable-theme_' . $_GET['theme']); $allowed_themes[ $_GET['theme'] ] = true; update_site_option( 'allowedthemes', $allowed_themes ); if ( false === strpos( $referer, '/network/themes.php' ) ) wp_redirect( network_admin_url( 'themes.php?enabled=1' ) ); else wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) ); exit; break; case 'disable': check_admin_referer('disable-theme_' . $_GET['theme']); unset( $allowed_themes[ $_GET['theme'] ] ); update_site_option( 'allowedthemes', $allowed_themes ); wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) ); exit; break; case 'enable-selected': check_admin_referer('bulk-themes'); $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); if ( empty($themes) ) { wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) ); exit; } foreach( (array) $themes as $theme ) $allowed_themes[ $theme ] = true; update_site_option( 'allowedthemes', $allowed_themes ); wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) ); exit; break; case 'disable-selected': check_admin_referer('bulk-themes'); $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); if ( empty($themes) ) { wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) ); exit; } foreach( (array) $themes as $theme ) unset( $allowed_themes[ $theme ] ); update_site_option( 'allowedthemes', $allowed_themes ); wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) ); exit; break; case 'update-selected' : check_admin_referer( 'bulk-themes' ); if ( isset( $_GET['themes'] ) ) $themes = explode( ',', $_GET['themes'] ); elseif ( isset( $_POST['checked'] ) ) $themes = (array) $_POST['checked']; else $themes = array(); $title = __( 'Update Themes' ); $parent_file = 'themes.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); echo '<div class="wrap">'; screen_icon(); echo '<h2>' . esc_html( $title ) . '</h2>'; $url = self_admin_url('update.php?action=update-selected-themes&amp;themes=' . urlencode( join(',', $themes) )); $url = wp_nonce_url($url, 'bulk-update-themes'); echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>"; echo '</div>'; require_once(ABSPATH . 'wp-admin/admin-footer.php'); exit; break; case 'delete-selected': if ( ! current_user_can( 'delete_themes' ) ) wp_die( __('You do not have sufficient permissions to delete themes for this site.') ); check_admin_referer( 'bulk-themes' ); $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array(); unset( $themes[ get_option( 'stylesheet' ) ], $themes[ get_option( 'template' ) ] ); if ( empty( $themes ) ) { wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) ); exit; } $files_to_delete = $theme_info = array(); foreach ( $themes as $key => $theme ) { $theme_info[ $theme ] = wp_get_theme( $theme ); $files_to_delete = array_merge( $files_to_delete, list_files( $theme_info[ $theme ]->get_stylesheet_directory() ) ); } if ( empty( $themes ) ) { wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) ); exit; } include(ABSPATH . 'wp-admin/update.php'); $parent_file = 'themes.php'; if ( ! isset( $_REQUEST['verify-delete'] ) ) { wp_enqueue_script( 'jquery' ); require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?> <div class="wrap"> <?php $themes_to_delete = count( $themes ); screen_icon(); echo '<h2>' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '</h2>'; ?> <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo _n( 'This theme may be active on other sites in the network.', 'These themes may be active on other sites in the network.', $themes_to_delete ); ?></p></div> <p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p> <ul class="ul-disc"> <?php foreach ( $theme_info as $theme ) echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>'; /* translators: 1: theme name, 2: theme author */ ?> </ul> <p><?php _e('Are you sure you wish to delete these themes?'); ?></p> <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;"> <input type="hidden" name="verify-delete" value="1" /> <input type="hidden" name="action" value="delete-selected" /> <?php foreach ( (array) $themes as $theme ) echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />'; ?> <?php wp_nonce_field('bulk-themes') ?> <?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?> </form> <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;"> <?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?> </form> <p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p> <div id="files-list" style="display:none;"> <ul class="code"> <?php foreach ( (array) $files_to_delete as $file ) echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>'; ?> </ul> </div> </div> <?php require_once(ABSPATH . 'wp-admin/admin-footer.php'); exit; } // Endif verify-delete foreach ( $themes as $theme ) $delete_result = delete_theme( $theme, esc_url( add_query_arg( array('verify-delete' => 1), $_SERVER['REQUEST_URI'] ) ) ); $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1; wp_redirect( network_admin_url( "themes.php?deleted=".count( $themes )."&paged=$paged&s=$s" ) ); exit; break; } } $wp_list_table->prepare_items(); add_thickbox(); add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' )) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.') . '</p>' . '<p>' . __('If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.') . '</p>' . '<p>' . __('Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); $title = __('Themes'); $parent_file = 'themes.php'; require_once(ABSPATH . 'wp-admin/admin-header.php'); ?> <div class="wrap"> <?php screen_icon('themes'); ?> <h2><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php } if ( $s ) printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?> </h2> <?php if ( isset( $_GET['enabled'] ) ) { $_GET['enabled'] = absint( $_GET['enabled'] ); echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>'; } elseif ( isset( $_GET['disabled'] ) ) { $_GET['disabled'] = absint( $_GET['disabled'] ); echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>'; } elseif ( isset( $_GET['deleted'] ) ) { $_GET['deleted'] = absint( $_GET['deleted'] ); echo '<div id="message" class="updated"><p>' . sprintf( _nx( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'], 'network' ), number_format_i18n( $_GET['deleted'] ) ) . '</p></div>'; } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) { echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>'; } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) { echo '<div class="error"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>'; } ?> <form method="get" action=""> <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?> </form> <?php $wp_list_table->views(); if ( 'broken' == $status ) echo '<p class="clear">' . __('The following themes are installed but incomplete. Themes must have a stylesheet and a template.') . '</p>'; ?> <form method="post" action=""> <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" /> <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" /> <?php $wp_list_table->display(); ?> </form> </div> <?php include(ABSPATH . 'wp-admin/admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/network/themes.php
PHP
oos
10,963
<?php /** * Add Site Administration Screen * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can('create_users') ) wp_die(__('You do not have sufficient permissions to add users to this network.')); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('Add User will set up a new user account on the network and send that person an email with username and password.') . '</p>' . '<p>' . __('Users who are signed up to the network without a site are added as subscribers to the main or primary dashboard site, giving them profile pages to manage their accounts. These users will only see Dashboard and My Sites in the main navigation until a site is created for them.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) { check_admin_referer( 'add-user', '_wpnonce_add-user' ); if ( ! current_user_can( 'manage_network_users' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); if ( ! is_array( $_POST['user'] ) ) wp_die( __( 'Cannot create an empty user.' ) ); $user = $_POST['user']; $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] ); if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) { $add_user_errors = $user_details[ 'errors' ]; } else { $password = wp_generate_password( 12, false); $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) ); if ( ! $user_id ) { $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) ); } else { wp_new_user_notification( $user_id, $password ); wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) ); exit; } } } if ( isset($_GET['update']) ) { $messages = array(); if ( 'added' == $_GET['update'] ) $messages[] = __('User added.'); } $title = __('Add New User'); $parent_file = 'users.php'; require('../admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2 id="add-new-user"><?php _e('Add New User') ?></h2> <?php if ( ! empty( $messages ) ) { foreach ( $messages as $msg ) echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; } if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) { ?> <div class="error"> <?php foreach ( $add_user_errors->get_error_messages() as $message ) echo "<p>$message</p>"; ?> </div> <?php } ?> <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post"> <table class="form-table"> <tr class="form-field form-required"> <th scope="row"><?php _e( 'Username' ) ?></th> <td><input type="text" class="regular-text" name="user[username]" /></td> </tr> <tr class="form-field form-required"> <th scope="row"><?php _e( 'Email' ) ?></th> <td><input type="text" class="regular-text" name="user[email]" /></td> </tr> <tr class="form-field"> <td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td> </tr> </table> <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ) ?> <?php submit_button( __('Add User'), 'primary', 'add-user' ); ?> </form> </div> <?php require('../admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/network/user-new.php
PHP
oos
3,852
<?php /** * User profile network administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../profile.php' );
01happy-blog
trunk/myblog/wp-admin/network/profile.php
PHP
oos
313
<?php /** * Multisite network settings administration panel. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can( 'manage_network_options' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $title = __( 'Network Settings' ); $parent_file = 'settings.php'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This screen sets and changes options for the network as a whole. The first site is the main site in the network and network options are pulled from that original site&#8217;s options.') . '</p>' . '<p>' . __('Operational settings has fields for the network&#8217;s name and admin email.') . '</p>' . '<p>' . __('Dashboard Site is an option to give a site to users who do not have a site on the system. Their default role is Subscriber, but that default can be changed. The Admin Notice Feed can provide a notice on all dashboards of the latest post via RSS or Atom, or provide no such notice if left blank.') . '</p>' . '<p>' . __('Registration settings can disable/enable public signups. If you let others sign up for a site, install spam plugins. Spaces, not commas, should separate names banned as sites for this network.') . '</p>' . '<p>' . __('New site settings are defaults applied when a new site is created in the network. These include welcome email for when a new site or user account is registered, and what&#8127;s put in the first post, page, comment, comment author, and comment URL.') . '</p>' . '<p>' . __('Upload settings control the size of the uploaded files and the amount of available upload space for each site. You can change the default value for specific sites when you edit a particular site. Allowed file types are also listed (space separated only).') . '</p>' . '<p>' . __('Menu setting enables/disables the plugin menus from appearing for non super admins, so that only super admins, not site admins, have access to activate plugins.') . '</p>' . '<p>' . __('Super admins can no longer be added on the Options screen. You must now go to the list of existing users on Network Admin > Users and click on Username or the Edit action link below that name. This goes to an Edit User page where you can check a box to grant super admin privileges.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Settings_Screen" target="_blank">Documentation on Network Settings</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); if ( $_POST ) { do_action( 'wpmuadminedit' , '' ); check_admin_referer( 'siteoptions' ); if ( isset( $_POST['WPLANG'] ) && ( '' === $_POST['WPLANG'] || in_array( $_POST['WPLANG'], get_available_languages() ) ) ) update_site_option( 'WPLANG', $_POST['WPLANG'] ); if ( is_email( $_POST['admin_email'] ) ) update_site_option( 'admin_email', $_POST['admin_email'] ); $illegal_names = explode( ' ', $_POST['illegal_names'] ); foreach ( (array) $illegal_names as $name ) { $name = trim( $name ); if ( $name != '' ) $names[] = trim( $name ); } update_site_option( 'illegal_names', $names ); if ( $_POST['limited_email_domains'] != '' ) { $limited_email_domains = str_replace( ' ', "\n", $_POST['limited_email_domains'] ); $limited_email_domains = explode( "\n", stripslashes( $limited_email_domains ) ); $limited_email = array(); foreach ( (array) $limited_email_domains as $domain ) { $domain = trim( $domain ); if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) ) $limited_email[] = trim( $domain ); } update_site_option( 'limited_email_domains', $limited_email ); } else { update_site_option( 'limited_email_domains', '' ); } if ( $_POST['banned_email_domains'] != '' ) { $banned_email_domains = explode( "\n", stripslashes( $_POST['banned_email_domains'] ) ); $banned = array(); foreach ( (array) $banned_email_domains as $domain ) { $domain = trim( $domain ); if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) ) $banned[] = trim( $domain ); } update_site_option( 'banned_email_domains', $banned ); } else { update_site_option( 'banned_email_domains', '' ); } $options = array( 'registrationnotification', 'registration', 'add_new_users', 'menu_items', 'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name', 'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author', 'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'global_terms_enabled' ); $checked_options = array( 'menu_items' => array(), 'registrationnotification' => 'no', 'upload_space_check_disabled' => 1, 'add_new_users' => 0 ); foreach ( $checked_options as $option_name => $option_unchecked_value ) { if ( ! isset( $_POST[$option_name] ) ) $_POST[$option_name] = $option_unchecked_value; } foreach ( $options as $option_name ) { if ( ! isset($_POST[$option_name]) ) continue; $value = stripslashes_deep( $_POST[$option_name] ); update_site_option( $option_name, $value ); } // Update more options here do_action( 'update_wpmu_options' ); wp_redirect( add_query_arg( 'updated', 'true', network_admin_url( 'settings.php' ) ) ); exit(); } include( '../admin-header.php' ); if ( isset( $_GET['updated'] ) ) { ?><div id="message" class="updated"><p><?php _e( 'Options saved.' ) ?></p></div><?php } ?> <div class="wrap"> <?php screen_icon('options-general'); ?> <h2><?php echo esc_html( $title ); ?></h2> <form method="post" action="settings.php"> <?php wp_nonce_field( 'siteoptions' ); ?> <h3><?php _e( 'Operational Settings' ); ?></h3> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="site_name"><?php _e( 'Network Name' ) ?></label></th> <td> <input name="site_name" type="text" id="site_name" class="regular-text" value="<?php echo esc_attr( $current_site->site_name ) ?>" /> <br /> <?php _e( 'What you would like to call this network.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="admin_email"><?php _e( 'Network Admin Email' ) ?></label></th> <td> <input name="admin_email" type="text" id="admin_email" class="regular-text" value="<?php echo esc_attr( get_site_option('admin_email') ) ?>" /> <br /> <?php printf( __( 'Registration and support emails will come from this address. An address such as <code>support@%s</code> is recommended.' ), $current_site->domain ); ?> </td> </tr> </table> <h3><?php _e( 'Registration Settings' ); ?></h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e( 'Allow new registrations' ) ?></th> <?php if ( !get_site_option( 'registration' ) ) update_site_option( 'registration', 'none' ); $reg = get_site_option( 'registration' ); ?> <td> <label><input name="registration" type="radio" id="registration1" value="none"<?php checked( $reg, 'none') ?> /> <?php _e( 'Registration is disabled.' ); ?></label><br /> <label><input name="registration" type="radio" id="registration2" value="user"<?php checked( $reg, 'user') ?> /> <?php _e( 'User accounts may be registered.' ); ?></label><br /> <label><input name="registration" type="radio" id="registration3" value="blog"<?php checked( $reg, 'blog') ?> /> <?php _e( 'Logged in users may register new sites.' ); ?></label><br /> <label><input name="registration" type="radio" id="registration4" value="all"<?php checked( $reg, 'all') ?> /> <?php _e( 'Both sites and user accounts can be registered.' ); ?></label><br /> <?php if ( is_subdomain_install() ) _e( 'If registration is disabled, please set <code>NOBLOGREDIRECT</code> in <code>wp-config.php</code> to a URL you will redirect visitors to if they visit a non-existent site.' ); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e( 'Registration notification' ) ?></th> <?php if ( !get_site_option( 'registrationnotification' ) ) update_site_option( 'registrationnotification', 'yes' ); ?> <td> <label><input name="registrationnotification" type="checkbox" id="registrationnotification" value="yes"<?php checked( get_site_option( 'registrationnotification' ), 'yes' ) ?> /> <?php _e( 'Send the network admin an email notification every time someone registers a site or user account.' ) ?></label> </td> </tr> <tr valign="top" id="addnewusers"> <th scope="row"><?php _e( 'Add New Users' ) ?></th> <td> <label><input name="add_new_users" type="checkbox" id="add_new_users" value="1"<?php checked( get_site_option( 'add_new_users' ) ) ?> /> <?php _e( 'Allow site administrators to add new users to their site via the "Users &rarr; Add New" page.' ); ?></label> </td> </tr> <tr valign="top"> <th scope="row"><label for="illegal_names"><?php _e( 'Banned Names' ) ?></label></th> <td> <input name="illegal_names" type="text" id="illegal_names" class="large-text" value="<?php echo esc_attr( implode( " ", (array) get_site_option( 'illegal_names' ) ) ); ?>" size="45" /> <br /> <?php _e( 'Users are not allowed to register these sites. Separate names by spaces.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="limited_email_domains"><?php _e( 'Limited Email Registrations' ) ?></label></th> <td> <?php $limited_email_domains = get_site_option( 'limited_email_domains' ); $limited_email_domains = str_replace( ' ', "\n", $limited_email_domains ); ?> <textarea name="limited_email_domains" id="limited_email_domains" cols="45" rows="5"> <?php echo esc_textarea( $limited_email_domains == '' ? '' : implode( "\n", (array) $limited_email_domains ) ); ?></textarea> <br /> <?php _e( 'If you want to limit site registrations to certain domains. One domain per line.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="banned_email_domains"><?php _e('Banned Email Domains') ?></label></th> <td> <textarea name="banned_email_domains" id="banned_email_domains" cols="45" rows="5"> <?php echo esc_textarea( get_site_option( 'banned_email_domains' ) == '' ? '' : implode( "\n", (array) get_site_option( 'banned_email_domains' ) ) ); ?></textarea> <br /> <?php _e( 'If you want to ban domains from site registrations. One domain per line.' ) ?> </td> </tr> </table> <h3><?php _e('New Site Settings'); ?></h3> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="welcome_email"><?php _e( 'Welcome Email' ) ?></label></th> <td> <textarea name="welcome_email" id="welcome_email" rows="5" cols="45" class="large-text"> <?php echo esc_textarea( stripslashes( get_site_option( 'welcome_email' ) ) ) ?></textarea> <br /> <?php _e( 'The welcome email sent to new site owners.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="welcome_user_email"><?php _e( 'Welcome User Email' ) ?></label></th> <td> <textarea name="welcome_user_email" id="welcome_user_email" rows="5" cols="45" class="large-text"> <?php echo esc_textarea( stripslashes( get_site_option( 'welcome_user_email' ) ) ) ?></textarea> <br /> <?php _e( 'The welcome email sent to new users.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="first_post"><?php _e( 'First Post' ) ?></label></th> <td> <textarea name="first_post" id="first_post" rows="5" cols="45" class="large-text"> <?php echo esc_textarea( stripslashes( get_site_option( 'first_post' ) ) ) ?></textarea> <br /> <?php _e( 'The first post on a new site.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="first_page"><?php _e( 'First Page' ) ?></label></th> <td> <textarea name="first_page" id="first_page" rows="5" cols="45" class="large-text"> <?php echo esc_textarea( stripslashes( get_site_option('first_page') ) ) ?></textarea> <br /> <?php _e( 'The first page on a new site.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="first_comment"><?php _e( 'First Comment' ) ?></label></th> <td> <textarea name="first_comment" id="first_comment" rows="5" cols="45" class="large-text"> <?php echo esc_textarea( stripslashes( get_site_option('first_comment') ) ) ?></textarea> <br /> <?php _e( 'The first comment on a new site.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="first_comment_author"><?php _e( 'First Comment Author' ) ?></label></th> <td> <input type="text" size="40" name="first_comment_author" id="first_comment_author" value="<?php echo get_site_option('first_comment_author') ?>" /> <br /> <?php _e( 'The author of the first comment on a new site.' ) ?> </td> </tr> <tr valign="top"> <th scope="row"><label for="first_comment_url"><?php _e( 'First Comment URL' ) ?></label></th> <td> <input type="text" size="40" name="first_comment_url" id="first_comment_url" value="<?php echo esc_attr( get_site_option( 'first_comment_url' ) ) ?>" /> <br /> <?php _e( 'The URL for the first comment on a new site.' ) ?> </td> </tr> </table> <h3><?php _e( 'Upload Settings' ); ?></h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e( 'Site upload space' ) ?></th> <td> <label><input type="checkbox" id="upload_space_check_disabled" name="upload_space_check_disabled" value="0"<?php checked( get_site_option( 'upload_space_check_disabled' ), 0 ) ?>/> <?php printf( __( 'Limit total size of files uploaded to %s MB' ), '</label><label><input name="blog_upload_space" type="number" min="0" style="width: 100px" id="blog_upload_space" value="' . esc_attr( get_site_option('blog_upload_space', 100) ) . '" />' ); ?></label><br /> </td> </tr> <tr valign="top"> <th scope="row"><label for="upload_filetypes"><?php _e( 'Upload file types' ) ?></label></th> <td><input name="upload_filetypes" type="text" id="upload_filetypes" class="large-text" value="<?php echo esc_attr( get_site_option('upload_filetypes', 'jpg jpeg png gif') ) ?>" size="45" /></td> </tr> <tr valign="top"> <th scope="row"><label for="fileupload_maxk"><?php _e( 'Max upload file size' ) ?></label></th> <td><?php printf( _x( '%s KB', 'File size in kilobytes' ), '<input name="fileupload_maxk" type="number" min="0" style="width: 100px" id="fileupload_maxk" value="' . esc_attr( get_site_option( 'fileupload_maxk', 300 ) ) . '" />' ); ?></td> </tr> </table> <?php $languages = get_available_languages(); if ( ! empty( $languages ) ) { $lang = get_site_option( 'WPLANG' ); ?> <h3><?php _e( 'Language Settings' ); ?></h3> <table class="form-table"> <tr valign="top"> <th><label for="WPLANG"><?php _e( 'Default Language' ); ?></label></th> <td> <select name="WPLANG" id="WPLANG"> <?php mu_dropdown_languages( $languages, get_site_option( 'WPLANG' ) ); ?> </select> </td> </tr> </table> <?php } // languages ?> <h3><?php _e( 'Menu Settings' ); ?></h3> <table id="menu" class="form-table"> <tr valign="top"> <th scope="row"><?php _e( 'Enable administration menus' ); ?></th> <td> <?php $menu_perms = get_site_option( 'menu_items' ); $menu_items = apply_filters( 'mu_menu_items', array( 'plugins' => __( 'Plugins' ) ) ); foreach ( (array) $menu_items as $key => $val ) { echo "<label><input type='checkbox' name='menu_items[" . $key . "]' value='1'" . ( isset( $menu_perms[$key] ) ? checked( $menu_perms[$key], '1', false ) : '' ) . " /> " . esc_html( $val ) . "</label><br/>"; } ?> </td> </tr> </table> <?php do_action( 'wpmu_options' ); // Add more options here ?> <?php submit_button(); ?> </form> </div> <?php include( '../admin-footer.php' ); ?>
01happy-blog
trunk/myblog/wp-admin/network/settings.php
PHP
oos
16,296
<?php /** * Network Credits administration panel. * * @package WordPress * @subpackage Multisite * @since 3.4.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../credits.php' );
01happy-blog
trunk/myblog/wp-admin/network/credits.php
PHP
oos
308
<?php /** * Install theme network administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ if ( isset( $_GET['tab'] ) && ( 'theme-information' == $_GET['tab'] ) ) define( 'IFRAME_REQUEST', true ); /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../theme-install.php' );
01happy-blog
trunk/myblog/wp-admin/network/theme-install.php
PHP
oos
428
<?php /** * Plugin editor network administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../plugin-editor.php' );
01happy-blog
trunk/myblog/wp-admin/network/plugin-editor.php
PHP
oos
321
<?php /** * WordPress Network Administration Bootstrap * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ define( 'WP_NETWORK_ADMIN', true ); /** Load WordPress Administration Bootstrap */ require_once( dirname( dirname( __FILE__ ) ) . '/admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); $redirect_network_admin_request = ( ( $current_blog->domain != $current_site->domain ) || ( $current_blog->path != $current_site->path ) ); $redirect_network_admin_request = apply_filters( 'redirect_network_admin_request', $redirect_network_admin_request ); if ( $redirect_network_admin_request ) { wp_redirect( network_admin_url() ); exit; } unset( $redirect_network_admin_request );
01happy-blog
trunk/myblog/wp-admin/network/admin.php
PHP
oos
741
<?php /** * Network Setup administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../network.php' );
01happy-blog
trunk/myblog/wp-admin/network/setup.php
PHP
oos
306
<?php /** * Network Plugins administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../plugins.php' );
01happy-blog
trunk/myblog/wp-admin/network/plugins.php
PHP
oos
308
<?php /** * Edit Site Themes Administration Screen * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); $menu_perms = get_site_option( 'menu_items', array() ); if ( empty( $menu_perms['themes'] ) && ! is_super_admin() ) wp_die( __( 'Cheatin&#8217; uh?' ) ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.') . '</p>' . '<p>' . __('<strong>Info</strong> - The domain and path are rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.') . '</p>' . '<p>' . __('<strong>Users</strong> - This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.') . '</p>' . '<p>' . sprintf( __('<strong>Themes</strong> - This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' . '<p>' . __('<strong>Settings</strong> - This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); $wp_list_table = _get_list_table('WP_MS_Themes_List_Table'); $action = $wp_list_table->current_action(); $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; // Clean up request URI from temporary args for screen options/paging uri's to work as expected. $temp_args = array( 'enabled', 'disabled', 'error' ); $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] ); $referer = remove_query_arg( $temp_args, wp_get_referer() ); $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; if ( ! $id ) wp_die( __('Invalid site ID.') ); $wp_list_table->prepare_items(); $details = get_blog_details( $id ); if ( !can_edit_network( $details->site_id ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $is_main_site = is_main_site( $id ); if ( $action ) { switch_to_blog( $id ); $allowed_themes = get_option( 'allowedthemes' ); switch ( $action ) { case 'enable': check_admin_referer( 'enable-theme_' . $_GET['theme'] ); $theme = $_GET['theme']; $action = 'enabled'; $n = 1; if ( !$allowed_themes ) $allowed_themes = array( $theme => true ); else $allowed_themes[$theme] = true; break; case 'disable': check_admin_referer( 'disable-theme_' . $_GET['theme'] ); $theme = $_GET['theme']; $action = 'disabled'; $n = 1; if ( !$allowed_themes ) $allowed_themes = array(); else unset( $allowed_themes[$theme] ); break; case 'enable-selected': check_admin_referer( 'bulk-themes' ); if ( isset( $_POST['checked'] ) ) { $themes = (array) $_POST['checked']; $action = 'enabled'; $n = count( $themes ); foreach( (array) $themes as $theme ) $allowed_themes[ $theme ] = true; } else { $action = 'error'; $n = 'none'; } break; case 'disable-selected': check_admin_referer( 'bulk-themes' ); if ( isset( $_POST['checked'] ) ) { $themes = (array) $_POST['checked']; $action = 'disabled'; $n = count( $themes ); foreach( (array) $themes as $theme ) unset( $allowed_themes[ $theme ] ); } else { $action = 'error'; $n = 'none'; } break; } update_option( 'allowedthemes', $allowed_themes ); restore_current_blog(); wp_safe_redirect( add_query_arg( array( 'id' => $id, $action => $n ), $referer ) ); exit; } if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) { wp_safe_redirect( $referer ); exit(); } add_thickbox(); add_screen_option( 'per_page', array( 'label' => _x( 'Themes', 'themes per page (screen options)' ) ) ); $site_url_no_http = preg_replace( '#^http(s)?://#', '', get_blogaddress_by_id( $id ) ); $title_site_url_linked = sprintf( __('Edit Site: <a href="%1$s">%2$s</a>'), get_blogaddress_by_id( $id ), $site_url_no_http ); $title = sprintf( __('Edit Site: %s'), $site_url_no_http ); $parent_file = 'sites.php'; $submenu_file = 'sites.php'; require('../admin-header.php'); ?> <div class="wrap"> <?php screen_icon('ms-admin'); ?> <h2 id="edit-site"><?php echo $title_site_url_linked ?></h2> <h3 class="nav-tab-wrapper"> <?php $tabs = array( 'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ), 'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ), 'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ), 'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ), ); foreach ( $tabs as $tab_id => $tab ) { $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : ''; echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>'; } ?> </h3><?php if ( isset( $_GET['enabled'] ) ) { $_GET['enabled'] = absint( $_GET['enabled'] ); echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>'; } elseif ( isset( $_GET['disabled'] ) ) { $_GET['disabled'] = absint( $_GET['disabled'] ); echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>'; } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) { echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>'; } ?> <p><?php _e( 'Network enabled themes are not shown on this screen.' ) ?></p> <form method="get" action=""> <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> </form> <?php $wp_list_table->views(); ?> <form method="post" action="site-themes.php?action=update-site"> <?php wp_nonce_field( 'edit-site' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> <?php $wp_list_table->display(); ?> </form> </div> <?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?>
01happy-blog
trunk/myblog/wp-admin/network/site-themes.php
PHP
oos
7,501
<?php /** * Edit Site Users Administration Screen * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can('manage_sites') ) wp_die(__('You do not have sufficient permissions to edit this site.')); $wp_list_table = _get_list_table('WP_Users_List_Table'); $wp_list_table->prepare_items(); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.') . '</p>' . '<p>' . __('<strong>Info</strong> - The domain and path are rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.') . '</p>' . '<p>' . __('<strong>Users</strong> - This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.') . '</p>' . '<p>' . sprintf( __('<strong>Themes</strong> - This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' . '<p>' . __('<strong>Settings</strong> - This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); $_SERVER['REQUEST_URI'] = remove_query_arg( 'update', $_SERVER['REQUEST_URI'] ); $referer = remove_query_arg( 'update', wp_get_referer() ); $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; if ( ! $id ) wp_die( __('Invalid site ID.') ); $details = get_blog_details( $id ); if ( !can_edit_network( $details->site_id ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $is_main_site = is_main_site( $id ); // get blog prefix $blog_prefix = $wpdb->get_blog_prefix( $id ); // @todo This is a hack. Eventually, add API to WP_Roles allowing retrieval of roles for a particular blog. if ( ! empty($wp_roles->use_db) ) { $editblog_roles = get_blog_option( $id, "{$blog_prefix}user_roles" ); } else { // Roles are stored in memory, not the DB. $editblog_roles = $wp_roles->roles; } $default_role = get_blog_option( $id, 'default_role' ); $action = $wp_list_table->current_action(); if ( $action ) { switch_to_blog( $id ); switch ( $action ) { case 'newuser': check_admin_referer( 'add-user', '_wpnonce_add-new-user' ); $user = $_POST['user']; if ( !is_array( $_POST['user'] ) || empty( $user['username'] ) || empty( $user['email'] ) ) { $update = 'err_new'; } else { $password = wp_generate_password( 12, false); $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) ); if ( false == $user_id ) { $update = 'err_new_dup'; } else { wp_new_user_notification( $user_id, $password ); add_user_to_blog( $id, $user_id, $_POST['new_role'] ); $update = 'newuser'; } } break; case 'adduser': check_admin_referer( 'add-user', '_wpnonce_add-user' ); if ( !empty( $_POST['newuser'] ) ) { $update = 'adduser'; $newuser = $_POST['newuser']; $userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) ); if ( $userid ) { $user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" ); if ( $user == false ) add_user_to_blog( $id, $userid, $_POST['new_role'] ); else $update = 'err_add_member'; } else { $update = 'err_add_notfound'; } } else { $update = 'err_add_notfound'; } break; case 'remove': if ( !current_user_can('remove_users') ) die(__('You can&#8217;t remove users.')); check_admin_referer( 'bulk-users' ); $update = 'remove'; if ( isset( $_REQUEST['users'] ) ) { $userids = $_REQUEST['users']; foreach ( $userids as $user_id ) { $user_id = (int) $user_id; remove_user_from_blog( $user_id, $id ); } } elseif ( isset( $_GET['user'] ) ) { remove_user_from_blog( $_GET['user'] ); } else { $update = 'err_remove'; } break; case 'promote': check_admin_referer( 'bulk-users' ); $editable_roles = get_editable_roles(); if ( empty( $editable_roles[$_REQUEST['new_role']] ) ) wp_die(__('You can&#8217;t give users that role.')); if ( isset( $_REQUEST['users'] ) ) { $userids = $_REQUEST['users']; $update = 'promote'; foreach ( $userids as $user_id ) { $user_id = (int) $user_id; // If the user doesn't already belong to the blog, bail. if ( !is_user_member_of_blog( $user_id ) ) wp_die(__('Cheatin&#8217; uh?')); $user = new WP_User( $user_id ); $user->set_role( $_REQUEST['new_role'] ); } } else { $update = 'err_promote'; } break; } restore_current_blog(); wp_safe_redirect( add_query_arg( 'update', $update, $referer ) ); exit(); } if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) { wp_safe_redirect( $referer ); exit(); } add_screen_option( 'per_page', array( 'label' => _x( 'Users', 'users per page (screen options)' ) ) ); $site_url_no_http = preg_replace( '#^http(s)?://#', '', get_blogaddress_by_id( $id ) ); $title_site_url_linked = sprintf( __('Edit Site: <a href="%1$s">%2$s</a>'), get_blogaddress_by_id( $id ), $site_url_no_http ); $title = sprintf( __('Edit Site: %s'), $site_url_no_http ); $parent_file = 'sites.php'; $submenu_file = 'sites.php'; if ( ! wp_is_large_network( 'users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) ) wp_enqueue_script( 'user-suggest' ); require('../admin-header.php'); ?> <script type='text/javascript'> /* <![CDATA[ */ var current_site_id = <?php echo $id; ?>; /* ]]> */ </script> <div class="wrap"> <?php screen_icon('ms-admin'); ?> <h2 id="edit-site"><?php echo $title_site_url_linked ?></h2> <h3 class="nav-tab-wrapper"> <?php $tabs = array( 'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ), 'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ), 'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ), 'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ), ); foreach ( $tabs as $tab_id => $tab ) { $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : ''; echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>'; } ?> </h3><?php if ( isset($_GET['update']) ) : switch($_GET['update']) { case 'adduser': echo '<div id="message" class="updated"><p>' . __( 'User added.' ) . '</p></div>'; break; case 'err_add_member': echo '<div id="message" class="error"><p>' . __( 'User is already a member of this site.' ) . '</p></div>'; break; case 'err_add_notfound': echo '<div id="message" class="error"><p>' . __( 'Enter the username of an existing user.' ) . '</p></div>'; break; case 'promote': echo '<div id="message" class="updated"><p>' . __( 'Changed roles.' ) . '</p></div>'; break; case 'err_promote': echo '<div id="message" class="error"><p>' . __( 'Select a user to change role.' ) . '</p></div>'; break; case 'remove': echo '<div id="message" class="updated"><p>' . __( 'User removed from this site.' ) . '</p></div>'; break; case 'err_remove': echo '<div id="message" class="error"><p>' . __( 'Select a user to remove.' ) . '</p></div>'; break; case 'newuser': echo '<div id="message" class="updated"><p>' . __( 'User created.' ) . '</p></div>'; break; case 'err_new': echo '<div id="message" class="error"><p>' . __( 'Enter the username and email.' ) . '</p></div>'; break; case 'err_new_dup': echo '<div id="message" class="error"><p>' . __( 'Duplicated username or email address.' ) . '</p></div>'; break; } endif; ?> <form class="search-form" action="" method="get"> <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> </form> <?php $wp_list_table->views(); ?> <form method="post" action="site-users.php?action=update-site"> <?php wp_nonce_field( 'edit-site' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> <?php $wp_list_table->display(); ?> </form> <?php do_action( 'network_site_users_after_list_table', '' );?> <?php if ( current_user_can( 'promote_users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) ) : ?> <h4 id="add-user"><?php _e('Add User to This Site') ?></h4> <?php if ( current_user_can( 'create_users' ) && apply_filters( 'show_network_site_users_add_new_form', true ) ) : ?> <p><?php _e( 'You may add from existing network users, or set up a new user to add to this site.' ); ?></p> <?php else : ?> <p><?php _e( 'You may add from existing network users to this site.' ); ?></p> <?php endif; ?> <h5 id="add-existing-user"><?php _e('Add Existing User') ?></h5> <form action="site-users.php?action=adduser" id="adduser" method="post"> <?php wp_nonce_field( 'edit-site' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> <table class="form-table"> <tr> <th scope="row"><?php _e( 'Username' ); ?></th> <td><input type="text" class="regular-text wp-suggest-user" name="newuser" id="newuser" /></td> </tr> <tr> <th scope="row"><?php _e( 'Role'); ?></th> <td><select name="new_role" id="new_role_0"> <?php reset( $editblog_roles ); foreach ( $editblog_roles as $role => $role_assoc ){ $name = translate_user_role( $role_assoc['name'] ); $selected = ( $role == $default_role ) ? 'selected="selected"' : ''; echo '<option ' . $selected . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>'; } ?> </select></td> </tr> </table> <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ) ?> <?php submit_button( __('Add User'), 'primary', 'add-user', false, array( 'id' => 'submit-add-existing-user' ) ); ?> </form> <?php endif; ?> <?php if ( current_user_can( 'create_users' ) && apply_filters( 'show_network_site_users_add_new_form', true ) ) : ?> <h5 id="add-new-user"><?php _e('Add New User') ?></h5> <form action="<?php echo network_admin_url('site-users.php?action=newuser'); ?>" id="newuser" method="post"> <?php wp_nonce_field( 'edit-site' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> <table class="form-table"> <tr> <th scope="row"><?php _e( 'Username' ) ?></th> <td><input type="text" class="regular-text" name="user[username]" /></td> </tr> <tr> <th scope="row"><?php _e( 'Email' ) ?></th> <td><input type="text" class="regular-text" name="user[email]" /></td> </tr> <tr> <th scope="row"><?php _e( 'Role'); ?></th> <td><select name="new_role" id="new_role_0"> <?php reset( $editblog_roles ); foreach ( $editblog_roles as $role => $role_assoc ){ $name = translate_user_role( $role_assoc['name'] ); $selected = ( $role == $default_role ) ? 'selected="selected"' : ''; echo '<option ' . $selected . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>'; } ?> </select></td> </tr> <tr class="form-field"> <td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td> </tr> </table> <?php wp_nonce_field( 'add-user', '_wpnonce_add-new-user' ) ?> <?php submit_button( __('Add New User'), 'primary', 'add-user', false, array( 'id' => 'submit-add-user' ) ); ?> </form> <?php endif; ?> </div> <?php require('../admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/network/site-users.php
PHP
oos
12,800
<?php /** * Theme editor network administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../theme-editor.php' );
01happy-blog
trunk/myblog/wp-admin/network/theme-editor.php
PHP
oos
318
<?php /** * Updates network administration panel. * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require( '../update-core.php' );
01happy-blog
trunk/myblog/wp-admin/network/update-core.php
PHP
oos
312
<?php /** * Add Site Administration Screen * * @package WordPress * @subpackage Multisite * @since 3.1.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have sufficient permissions to add sites to this network.' ) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This screen is for Super Admins to add new sites to the network. This is not affected by the registration settings.') . '</p>' . '<p>' . __('If the admin email for the new site does not exist in the database, a new user will also be created.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) { check_admin_referer( 'add-blog', '_wpnonce_add-blog' ); if ( ! current_user_can( 'manage_sites' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); if ( ! is_array( $_POST['blog'] ) ) wp_die( __( 'Can&#8217;t create an empty site.' ) ); $blog = $_POST['blog']; $domain = ''; if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) ) $domain = strtolower( $blog['domain'] ); // If not a subdomain install, make sure the domain isn't a reserved word if ( ! is_subdomain_install() ) { $subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) ); if ( in_array( $domain, $subdirectory_reserved_names ) ) wp_die( sprintf( __('The following words are reserved for use by WordPress functions and cannot be used as blog names: <code>%s</code>' ), implode( '</code>, <code>', $subdirectory_reserved_names ) ) ); } $email = sanitize_email( $blog['email'] ); $title = $blog['title']; if ( empty( $domain ) ) wp_die( __( 'Missing or invalid site address.' ) ); if ( empty( $email ) ) wp_die( __( 'Missing email address.' ) ); if ( !is_email( $email ) ) wp_die( __( 'Invalid email address.' ) ); if ( is_subdomain_install() ) { $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain ); $path = $base; } else { $newdomain = $current_site->domain; $path = $base . $domain . '/'; } $password = 'N/A'; $user_id = email_exists($email); if ( !$user_id ) { // Create a new user with a random password $password = wp_generate_password( 12, false ); $user_id = wpmu_create_user( $domain, $password, $email ); if ( false == $user_id ) wp_die( __( 'There was an error creating the user.' ) ); else wp_new_user_notification( $user_id, $password ); } $wpdb->hide_errors(); $id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id ); $wpdb->show_errors(); if ( !is_wp_error( $id ) ) { if ( !is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) update_user_option( $user_id, 'primary_blog', $id, true ); $content_mail = sprintf( __( "New site created by %1s\n\nAddress: %2s\nName: %3s"), $current_user->user_login , get_site_url( $id ), stripslashes( $title ) ); wp_mail( get_site_option('admin_email'), sprintf( __( '[%s] New Site Created' ), $current_site->site_name ), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' ); wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) ); wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) ); exit; } else { wp_die( $id->get_error_message() ); } } if ( isset($_GET['update']) ) { $messages = array(); if ( 'added' == $_GET['update'] ) $messages[] = sprintf( __( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ), esc_url( get_admin_url( absint( $_GET['id'] ) ) ), network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) ) ); } $title = __('Add New Site'); $parent_file = 'sites.php'; require('../admin-header.php'); ?> <div class="wrap"> <?php screen_icon('ms-admin'); ?> <h2 id="add-new-site"><?php _e('Add New Site') ?></h2> <?php if ( ! empty( $messages ) ) { foreach ( $messages as $msg ) echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; } ?> <form method="post" action="<?php echo network_admin_url('site-new.php?action=add-site'); ?>"> <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?> <table class="form-table"> <tr class="form-field form-required"> <th scope="row"><?php _e( 'Site Address' ) ?></th> <td> <?php if ( is_subdomain_install() ) { ?> <input name="blog[domain]" type="text" class="regular-text" title="<?php esc_attr_e( 'Domain' ) ?>"/><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', $current_site->domain ); ?></span> <?php } else { echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php esc_attr_e( 'Domain' ) ?>"/> <?php } echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>'; ?> </td> </tr> <tr class="form-field form-required"> <th scope="row"><?php _e( 'Site Title' ) ?></th> <td><input name="blog[title]" type="text" class="regular-text" title="<?php esc_attr_e( 'Title' ) ?>"/></td> </tr> <tr class="form-field form-required"> <th scope="row"><?php _e( 'Admin Email' ) ?></th> <td><input name="blog[email]" type="text" class="regular-text" title="<?php esc_attr_e( 'Email' ) ?>"/></td> </tr> <tr class="form-field"> <td colspan="2"><?php _e( 'A new user will be created if the above email address is not in the database.' ) ?><br /><?php _e( 'The username and password will be mailed to this email address.' ) ?></td> </tr> </table> <?php submit_button( __('Add Site'), 'primary', 'add-site' ); ?> </form> </div> <?php require('../admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/network/site-new.php
PHP
oos
6,268
<?php /** * Multisite upgrade administration panel. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); require_once( ABSPATH . WPINC . '/http.php' ); $title = __( 'Update Network' ); $parent_file = 'upgrade.php'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('Only use this screen once you have updated to a new version of WordPress through Updates/Available Updates (via the Network Administration navigation menu or the Toolbar). Clicking the Update Network button will step through each site in the network, five at a time, and make sure any database updates are applied.') . '</p>' . '<p>' . __('If a version update to core has not happened, clicking this button won&#8217;t affect anything.') . '</p>' . '<p>' . __('If this process fails for any reason, users logging in to their sites will force the same update.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Updates_Screen" target="_blank">Documentation on Update Network</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); require_once('../admin-header.php'); if ( ! current_user_can( 'manage_network' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); echo '<div class="wrap">'; screen_icon('tools'); echo '<h2>' . __( 'Update Network' ) . '</h2>'; $action = isset($_GET['action']) ? $_GET['action'] : 'show'; switch ( $action ) { case "upgrade": $n = ( isset($_GET['n']) ) ? intval($_GET['n']) : 0; if ( $n < 5 ) { global $wp_db_version; update_site_option( 'wpmu_upgrade_site', $wp_db_version ); } $blogs = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A ); if ( empty( $blogs ) ) { echo '<p>' . __( 'All done!' ) . '</p>'; break; } echo "<ul>"; foreach ( (array) $blogs as $details ) { $siteurl = get_blog_option( $details['blog_id'], 'siteurl' ); echo "<li>$siteurl</li>"; $response = wp_remote_get( trailingslashit( $siteurl ) . "wp-admin/upgrade.php?step=upgrade_db", array( 'timeout' => 120, 'httpversion' => '1.1' ) ); if ( is_wp_error( $response ) ) wp_die( sprintf( __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>' ), $siteurl, $response->get_error_message() ) ); do_action( 'after_mu_upgrade', $response ); do_action( 'wpmu_upgrade_site', $details[ 'blog_id' ] ); } echo "</ul>"; ?><p><?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this link:' ); ?> <a class="button" href="upgrade.php?action=upgrade&amp;n=<?php echo ($n + 5) ?>"><?php _e("Next Sites"); ?></a></p> <script type='text/javascript'> <!-- function nextpage() { location.href = "upgrade.php?action=upgrade&n=<?php echo ($n + 5) ?>"; } setTimeout( "nextpage()", 250 ); //--> </script><?php break; case 'show': default: ?><p><?php _e( 'You can update all the sites on your network through this page. It works by calling the update script of each site automatically. Hit the link below to update.' ); ?></p> <p><a class="button" href="upgrade.php?action=upgrade"><?php _e("Update Network"); ?></a></p><?php do_action( 'wpmu_upgrade_page' ); break; } ?> </div> <?php include('../admin-footer.php'); ?>
01happy-blog
trunk/myblog/wp-admin/network/upgrade.php
PHP
oos
3,776
<?php /** * Multisite users administration panel. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ /** Load WordPress Administration Bootstrap */ require_once( './admin.php' ); if ( ! is_multisite() ) wp_die( __( 'Multisite support is not enabled.' ) ); if ( ! current_user_can( 'manage_network_users' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); function confirm_delete_users( $users ) { $current_user = wp_get_current_user(); if ( !is_array( $users ) ) return false; screen_icon(); ?> <h2><?php esc_html_e( 'Users' ); ?></h2> <p><?php _e( 'Transfer or delete posts and links before deleting users.' ); ?></p> <form action="users.php?action=dodelete" method="post"> <input type="hidden" name="dodelete" /> <?php wp_nonce_field( 'ms-users-delete' ); $site_admins = get_super_admins(); $admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>"; foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) { if ( $val != '' && $val != '0' ) { $delete_user = new WP_User( $val ); if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) ); if ( in_array( $delete_user->user_login, $site_admins ) ) wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), $delete_user->user_login ) ); echo "<input type='hidden' name='user[]' value='{$val}'/>\n"; $blogs = get_blogs_of_user( $val, true ); if ( !empty( $blogs ) ) { ?> <br /><fieldset><p><legend><?php printf( __( "What should be done with posts and links owned by <em>%s</em>?" ), $delete_user->user_login ); ?></legend></p> <?php foreach ( (array) $blogs as $key => $details ) { $blog_users = get_users( array( 'blog_id' => $details->userblog_id ) ); if ( is_array( $blog_users ) && !empty( $blog_users ) ) { $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>"; $user_dropdown = "<select name='blog[$val][{$key}]'>"; $user_list = ''; foreach ( $blog_users as $user ) { if ( ! in_array( $user->ID, $allusers ) ) $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>"; } if ( '' == $user_list ) $user_list = $admin_out; $user_dropdown .= $user_list; $user_dropdown .= "</select>\n"; ?> <ul style="list-style:none;"> <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li> <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" /> <?php _e( 'Delete all posts and links.' ); ?></label></li> <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" /> <?php echo __( 'Attribute all posts and links to:' ) . '</label>' . $user_dropdown; ?></li> </ul> <?php } } echo "</fieldset>"; } } } submit_button( __('Confirm Deletion'), 'delete' ); ?> </form> <?php return true; } if ( isset( $_GET['action'] ) ) { do_action( 'wpmuadminedit' , '' ); switch ( $_GET['action'] ) { case 'deleteuser': if ( ! current_user_can( 'manage_network_users' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); check_admin_referer( 'deleteuser' ); $id = intval( $_GET['id'] ); if ( $id != '0' && $id != '1' ) { $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays $title = __( 'Users' ); $parent_file = 'users.php'; require_once( '../admin-header.php' ); echo '<div class="wrap">'; confirm_delete_users( $_POST['allusers'] ); echo '</div>'; require_once( '../admin-footer.php' ); } else { wp_redirect( network_admin_url( 'users.php' ) ); } exit(); break; case 'allusers': if ( !current_user_can( 'manage_network_users' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) { check_admin_referer( 'bulk-users-network' ); $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2']; $userfunction = ''; foreach ( (array) $_POST['allusers'] as $key => $val ) { if ( !empty( $val ) ) { switch ( $doaction ) { case 'delete': if ( ! current_user_can( 'delete_users' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $title = __( 'Users' ); $parent_file = 'users.php'; require_once( '../admin-header.php' ); echo '<div class="wrap">'; confirm_delete_users( $_POST['allusers'] ); echo '</div>'; require_once( '../admin-footer.php' ); exit(); break; case 'spam': $user = new WP_User( $val ); if ( in_array( $user->user_login, get_super_admins() ) ) wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) ); $userfunction = 'all_spam'; $blogs = get_blogs_of_user( $val, true ); foreach ( (array) $blogs as $key => $details ) { if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam ! update_blog_status( $details->userblog_id, 'spam', '1' ); } update_user_status( $val, 'spam', '1' ); break; case 'notspam': $userfunction = 'all_notspam'; $blogs = get_blogs_of_user( $val, true ); foreach ( (array) $blogs as $key => $details ) update_blog_status( $details->userblog_id, 'spam', '0' ); update_user_status( $val, 'spam', '0' ); break; } } } wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) ); } else { $location = network_admin_url( 'users.php' ); if ( ! empty( $_REQUEST['paged'] ) ) $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location ); wp_redirect( $location ); } exit(); break; case 'dodelete': check_admin_referer( 'ms-users-delete' ); if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) wp_die( __( 'You do not have permission to access this page.' ) ); if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) { foreach ( $_POST['blog'] as $id => $users ) { foreach ( $users as $blogid => $user_id ) { if ( ! current_user_can( 'delete_user', $id ) ) continue; if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] ) remove_user_from_blog( $id, $blogid, $user_id ); else remove_user_from_blog( $id, $blogid ); } } } $i = 0; if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) foreach( $_POST['user'] as $id ) { if ( ! current_user_can( 'delete_user', $id ) ) continue; wpmu_delete_user( $id ); $i++; } if ( $i == 1 ) $deletefunction = 'delete'; else $deletefunction = 'all_delete'; wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) ); exit(); break; } } $wp_list_table = _get_list_table('WP_MS_Users_List_Table'); $pagenum = $wp_list_table->get_pagenum(); $wp_list_table->prepare_items(); $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); if ( $pagenum > $total_pages && $total_pages > 0 ) { wp_redirect( add_query_arg( 'paged', $total_pages ) ); exit; } $title = __( 'Users' ); $parent_file = 'users.php'; add_screen_option( 'per_page', array('label' => _x( 'Users', 'users per page (screen options)' )) ); get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' . '<p>' . __('Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to his or her Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.') . '</p>' . '<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' . '<p>' . __('You can sort the table by clicking on any of the bold headings and switch between list and excerpt views by using the icons in the upper right.') . '</p>' . '<p>' . __('The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.') . '</p>' . '<p>' . __('You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.') . '</p>' ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' ); require_once( '../admin-header.php' ); if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) { ?> <div id="message" class="updated"><p> <?php switch ( $_REQUEST['action'] ) { case 'delete': _e( 'User deleted.' ); break; case 'all_spam': _e( 'Users marked as spam.' ); break; case 'all_notspam': _e( 'Users removed from spam.' ); break; case 'all_delete': _e( 'Users deleted.' ); break; case 'add': _e( 'User added.' ); break; } ?> </p></div> <?php } ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php esc_html_e( 'Users' ); if ( current_user_can( 'create_users') ) : ?> <a href="<?php echo network_admin_url('user-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php endif; if ( !empty( $usersearch ) ) printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) ); ?> </h2> <?php $wp_list_table->views(); ?> <form action="" method="get" class="search-form"> <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?> </form> <form id="form-user-list" action='users.php?action=allusers' method='post'> <?php $wp_list_table->display(); ?> </form> </div> <?php require_once( '../admin-footer.php' ); ?>
01happy-blog
trunk/myblog/wp-admin/network/users.php
PHP
oos
10,863
<?php /** * Credits administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once( './admin.php' ); $title = __( 'Credits' ); function wp_credits() { global $wp_version; $locale = get_locale(); $results = get_site_transient( 'wordpress_credits_' . $locale ); if ( ! is_array( $results ) || ( isset( $results['data']['version'] ) && strpos( $wp_version, $results['data']['version'] ) !== 0 ) ) { $response = wp_remote_get( "http://api.wordpress.org/core/credits/1.0/?version=$wp_version&locale=$locale" ); if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) return false; $results = maybe_unserialize( wp_remote_retrieve_body( $response ) ); if ( ! is_array( $results ) ) return false; set_site_transient( 'wordpress_credits_' . $locale, $results, 86400 ); // One day } return $results; } function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) { $display_name = '<a href="' . esc_url( sprintf( $profiles, $username ) ) . '">' . esc_html( $display_name ) . '</a>'; } function _wp_credits_build_object_link( &$data ) { $data = '<a href="' . esc_url( $data[1] ) . '">' . $data[0] . '</a>'; } list( $display_version ) = explode( '-', $wp_version ); include( ABSPATH . 'wp-admin/admin-header.php' ); ?> <div class="wrap about-wrap"> <h1><?php printf( __( 'Welcome to WordPress %s' ), $display_version ); ?></h1> <div class="about-text"><?php printf( __( 'Thank you for updating to the latest version! WordPress %s is already making your website better, faster, and more attractive, just like you!' ), $display_version ); ?></div> <div class="wp-badge"><?php printf( __( 'Version %s' ), $display_version ); ?></div> <h2 class="nav-tab-wrapper"> <a href="about.php" class="nav-tab"> <?php _e( 'What&#8217;s New' ); ?> </a><a href="credits.php" class="nav-tab nav-tab-active"> <?php _e( 'Credits' ); ?> </a><a href="freedoms.php" class="nav-tab"> <?php _e( 'Freedoms' ); ?> </a> </h2> <?php $credits = wp_credits(); if ( ! $credits ) { echo '<p class="about-description">' . sprintf( __( 'WordPress is created by a <a href="%1$s">worldwide team</a> of passionate individuals. <a href="%2$s">Get involved in WordPress</a>.' ), 'http://wordpress.org/about/', /* translators: Url to the codex documentation on contributing to WordPress used on the credits page */ __( 'http://codex.wordpress.org/Contributing_to_WordPress' ) ) . '</p>'; include( ABSPATH . 'wp-admin/admin-footer.php' ); exit; } echo '<p class="about-description">' . __( 'WordPress is created by a worldwide team of passionate individuals.' ) . "</p>\n"; $gravatar = is_ssl() ? 'https://secure.gravatar.com/avatar/' : 'http://0.gravatar.com/avatar/'; foreach ( $credits['groups'] as $group_slug => $group_data ) { if ( $group_data['name'] ) { if ( 'Translators' == $group_data['name'] ) { // Considered a special slug in the API response. (Also, will never be returned for en_US.) $title = _x( 'Translators', 'Translate this to be the equivalent of English Translators in your language for the credits page Translators section' ); } elseif ( isset( $group_data['placeholders'] ) ) { $title = vsprintf( translate( $group_data['name'] ), $group_data['placeholders'] ); } else { $title = translate( $group_data['name'] ); } echo '<h4 class="wp-people-group">' . $title . "</h4>\n"; } if ( ! empty( $group_data['shuffle'] ) ) shuffle( $group_data['data'] ); // We were going to sort by ability to pronounce "hierarchical," but that wouldn't be fair to Matt. switch ( $group_data['type'] ) { case 'list' : array_walk( $group_data['data'], '_wp_credits_add_profile_link', $credits['data']['profiles'] ); echo '<p class="wp-credits-list">' . wp_sprintf( '%l.', $group_data['data'] ) . "</p>\n\n"; break; case 'libraries' : array_walk( $group_data['data'], '_wp_credits_build_object_link' ); echo '<p class="wp-credits-list">' . wp_sprintf( '%l.', $group_data['data'] ) . "</p>\n\n"; break; default: $compact = 'compact' == $group_data['type']; $classes = 'wp-people-group ' . ( $compact ? 'compact' : '' ); echo '<ul class="' . $classes . '" id="wp-people-group-' . $group_slug . '">' . "\n"; foreach ( $group_data['data'] as $person_data ) { echo '<li class="wp-person" id="wp-person-' . $person_data[2] . '">' . "\n\t"; echo '<a href="' . sprintf( $credits['data']['profiles'], $person_data[2] ) . '">'; $size = 'compact' == $group_data['type'] ? '30' : '60'; echo '<img src="' . $gravatar . $person_data[1] . '?s=' . $size . '" class="gravatar" alt="' . esc_attr( $person_data[0] ) . '" /></a>' . "\n\t"; echo '<a class="web" href="' . sprintf( $credits['data']['profiles'], $person_data[2] ) . '">' . $person_data[0] . "</a>\n\t"; if ( ! $compact ) echo '<span class="title">' . translate( $person_data[3] ) . "</span>\n"; echo "</li>\n"; } echo "</ul>\n"; break; } } ?> <p class="clear"><?php printf( __( 'Want to see your name in lights on this page? <a href="%s">Get involved in WordPress</a>.' ), /* translators: Url to the codex documentation on contributing to WordPress used on the credits page */ __( 'http://codex.wordpress.org/Contributing_to_WordPress' ) ); ?></p> </div> <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); return; // These are strings returned by the API that we want to be translatable __( 'Project Leaders' ); __( 'Extended Core Team' ); __( 'Core Developers' ); __( 'Recent Rockstars' ); __( 'Core Contributors to WordPress %s' ); __( 'Contributing Developers' ); __( 'Cofounder, Project Lead' ); __( 'Lead Developer' ); __( 'User Experience Lead' ); __( 'Core Developer' ); __( 'Core Committer' ); __( 'Guest Committer' ); __( 'Developer' ); __( 'Designer' ); __( 'XML-RPC' ); __( 'Internationalization' ); __( 'External Libraries' ); __( 'Icon Design' );
01happy-blog
trunk/myblog/wp-admin/credits.php
PHP
oos
5,965
<?php /** * General settings administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); if ( ! current_user_can( 'manage_options' ) ) wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) ); $title = __('General Settings'); $parent_file = 'options-general.php'; /* translators: date and time format for exact current time, mainly about timezones, see http://php.net/date */ $timezone_format = _x('Y-m-d G:i:s', 'timezone date format'); /** * Display JavaScript on the page. * * @package WordPress * @subpackage General_Settings_Screen */ function add_js() { ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready(function($){ $("input[name='date_format']").click(function(){ if ( "date_format_custom_radio" != $(this).attr("id") ) $("input[name='date_format_custom']").val( $(this).val() ).siblings('.example').text( $(this).siblings('span').text() ); }); $("input[name='date_format_custom']").focus(function(){ $("#date_format_custom_radio").attr("checked", "checked"); }); $("input[name='time_format']").click(function(){ if ( "time_format_custom_radio" != $(this).attr("id") ) $("input[name='time_format_custom']").val( $(this).val() ).siblings('.example').text( $(this).siblings('span').text() ); }); $("input[name='time_format_custom']").focus(function(){ $("#time_format_custom_radio").attr("checked", "checked"); }); $("input[name='date_format_custom'], input[name='time_format_custom']").change( function() { var format = $(this); format.siblings('img').css('visibility','visible'); $.post(ajaxurl, { action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format', date : format.val() }, function(d) { format.siblings('img').css('visibility','hidden'); format.siblings('.example').text(d); } ); }); }); //]]> </script> <?php } add_action('admin_head', 'add_js'); $options_help = '<p>' . __('The fields on this screen determine some of the basics of your site setup.') . '</p>' . '<p>' . __('Most themes display the site title at the top of every page, in the title bar of the browser, and as the identifying name for syndicated feeds. The tagline is also displayed by many themes.') . '</p>'; if ( ! is_multisite() ) { $options_help .= '<p>' . __('The WordPress URL and the Site URL can be the same (example.com) or different; for example, having the WordPress core files (example.com/wordpress) in a subdirectory instead of the root directory.') . '</p>' . '<p>' . __('If you want site visitors to be able to register themselves, as opposed to by the site administrator, check the membership box. A default user role can be set for all new users, whether self-registered or registered by the site admin.') . '</p>'; } $options_help .= '<p>' . __('UTC means Coordinated Universal Time.') . '</p>' . '<p>' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => $options_help, ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Settings_General_Screen" target="_blank">Documentation on General Settings</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); include('./admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <form method="post" action="options.php"> <?php settings_fields('general'); ?> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="blogname"><?php _e('Site Title') ?></label></th> <td><input name="blogname" type="text" id="blogname" value="<?php form_option('blogname'); ?>" class="regular-text" /></td> </tr> <tr valign="top"> <th scope="row"><label for="blogdescription"><?php _e('Tagline') ?></label></th> <td><input name="blogdescription" type="text" id="blogdescription" value="<?php form_option('blogdescription'); ?>" class="regular-text" /> <p class="description"><?php _e('In a few words, explain what this site is about.') ?></p></td> </tr> <?php if ( !is_multisite() ) { ?> <tr valign="top"> <th scope="row"><label for="siteurl"><?php _e('WordPress Address (URL)') ?></label></th> <td><input name="siteurl" type="text" id="siteurl" value="<?php form_option('siteurl'); ?>"<?php disabled( defined( 'WP_SITEURL' ) ); ?> class="regular-text code<?php if ( defined( 'WP_SITEURL' ) ) echo ' disabled' ?>" /></td> </tr> <tr valign="top"> <th scope="row"><label for="home"><?php _e('Site Address (URL)') ?></label></th> <td><input name="home" type="text" id="home" value="<?php form_option('home'); ?>"<?php disabled( defined( 'WP_HOME' ) ); ?> class="regular-text code<?php if ( defined( 'WP_HOME' ) ) echo ' disabled' ?>" /> <p class="description"><?php _e('Enter the address here if you want your site homepage <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">to be different from the directory</a> you installed WordPress.'); ?></p></td> </tr> <tr valign="top"> <th scope="row"><label for="admin_email"><?php _e('E-mail Address') ?> </label></th> <td><input name="admin_email" type="text" id="admin_email" value="<?php form_option('admin_email'); ?>" class="regular-text ltr" /> <p class="description"><?php _e('This address is used for admin purposes, like new user notification.') ?></p></td> </tr> <tr valign="top"> <th scope="row"><?php _e('Membership') ?></th> <td> <fieldset><legend class="screen-reader-text"><span><?php _e('Membership') ?></span></legend><label for="users_can_register"> <input name="users_can_register" type="checkbox" id="users_can_register" value="1" <?php checked('1', get_option('users_can_register')); ?> /> <?php _e('Anyone can register') ?></label> </fieldset></td> </tr> <tr valign="top"> <th scope="row"><label for="default_role"><?php _e('New User Default Role') ?></label></th> <td> <select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option('default_role') ); ?></select> </td> </tr> <?php } else { ?> <tr valign="top"> <th scope="row"><label for="new_admin_email"><?php _e('E-mail Address') ?> </label></th> <td><input name="new_admin_email" type="text" id="new_admin_email" value="<?php form_option('admin_email'); ?>" class="regular-text ltr" /> <p class="description"><?php _e('This address is used for admin purposes. If you change this we will send you an e-mail at your new address to confirm it. <strong>The new address will not become active until confirmed.</strong>') ?></p> <?php $new_admin_email = get_option( 'new_admin_email' ); if ( $new_admin_email && $new_admin_email != get_option('admin_email') ) : ?> <div class="updated inline"> <p><?php printf( __('There is a pending change of the admin e-mail to <code>%1$s</code>. <a href="%2$s">Cancel</a>'), esc_html( $new_admin_email ), esc_url( admin_url( 'options.php?dismiss=new_admin_email' ) ) ); ?></p> </div> <?php endif; ?> </td> </tr> <?php } ?> <tr> <?php $current_offset = get_option('gmt_offset'); $tzstring = get_option('timezone_string'); $check_zone_info = true; // Remove old Etc mappings. Fallback to gmt_offset. if ( false !== strpos($tzstring,'Etc/GMT') ) $tzstring = ''; if ( empty($tzstring) ) { // Create a UTC+- zone if no timezone string exists $check_zone_info = false; if ( 0 == $current_offset ) $tzstring = 'UTC+0'; elseif ($current_offset < 0) $tzstring = 'UTC' . $current_offset; else $tzstring = 'UTC+' . $current_offset; } ?> <th scope="row"><label for="timezone_string"><?php _e('Timezone') ?></label></th> <td> <select id="timezone_string" name="timezone_string"> <?php echo wp_timezone_choice($tzstring); ?> </select> <span id="utc-time"><?php printf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), date_i18n($timezone_format, false, 'gmt')); ?></span> <?php if ( get_option('timezone_string') || !empty($current_offset) ) : ?> <span id="local-time"><?php printf(__('Local time is <code>%1$s</code>'), date_i18n($timezone_format)); ?></span> <?php endif; ?> <p class="description"><?php _e('Choose a city in the same timezone as you.'); ?></p> <?php if ($check_zone_info && $tzstring) : ?> <br /> <span> <?php // Set TZ so localtime works. date_default_timezone_set($tzstring); $now = localtime(time(), true); if ( $now['tm_isdst'] ) _e('This timezone is currently in daylight saving time.'); else _e('This timezone is currently in standard time.'); ?> <br /> <?php $allowed_zones = timezone_identifiers_list(); if ( in_array( $tzstring, $allowed_zones) ) { $found = false; $date_time_zone_selected = new DateTimeZone($tzstring); $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); $right_now = time(); foreach ( timezone_transitions_get($date_time_zone_selected) as $tr) { if ( $tr['ts'] > $right_now ) { $found = true; break; } } if ( $found ) { echo ' '; $message = $tr['isdst'] ? __('Daylight saving time begins on: <code>%s</code>.') : __('Standard time begins on: <code>%s</code>.'); // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). printf( $message, date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $tr['ts'] + ($tz_offset - $tr['offset']) ) ); } else { _e('This timezone does not observe daylight saving time.'); } } // Set back to UTC. date_default_timezone_set('UTC'); ?> </span> <?php endif; ?> </td> </tr> <tr> <th scope="row"><?php _e('Date Format') ?></th> <td> <fieldset><legend class="screen-reader-text"><span><?php _e('Date Format') ?></span></legend> <?php $date_formats = apply_filters( 'date_formats', array( __('F j, Y'), 'Y/m/d', 'm/d/Y', 'd/m/Y', ) ); $custom = true; foreach ( $date_formats as $format ) { echo "\t<label title='" . esc_attr($format) . "'><input type='radio' name='date_format' value='" . esc_attr($format) . "'"; if ( get_option('date_format') === $format ) { // checked() uses "==" rather than "===" echo " checked='checked'"; $custom = false; } echo ' /> <span>' . date_i18n( $format ) . "</span></label><br />\n"; } echo ' <label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"'; checked( $custom ); echo '/> ' . __('Custom:') . ' </label><input type="text" name="date_format_custom" value="' . esc_attr( get_option('date_format') ) . '" class="small-text" /> <span class="example"> ' . date_i18n( get_option('date_format') ) . "</span> <img class='ajax-loading' src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' />\n"; echo "\t<p>" . __('<a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date and time formatting</a>.') . "</p>\n"; ?> </fieldset> </td> </tr> <tr> <th scope="row"><?php _e('Time Format') ?></th> <td> <fieldset><legend class="screen-reader-text"><span><?php _e('Time Format') ?></span></legend> <?php $time_formats = apply_filters( 'time_formats', array( __('g:i a'), 'g:i A', 'H:i', ) ); $custom = true; foreach ( $time_formats as $format ) { echo "\t<label title='" . esc_attr($format) . "'><input type='radio' name='time_format' value='" . esc_attr($format) . "'"; if ( get_option('time_format') === $format ) { // checked() uses "==" rather than "===" echo " checked='checked'"; $custom = false; } echo ' /> <span>' . date_i18n( $format ) . "</span></label><br />\n"; } echo ' <label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"'; checked( $custom ); echo '/> ' . __('Custom:') . ' </label><input type="text" name="time_format_custom" value="' . esc_attr( get_option('time_format') ) . '" class="small-text" /> <span class="example"> ' . date_i18n( get_option('time_format') ) . "</span> <img class='ajax-loading' src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' />\n"; ; ?> </fieldset> </td> </tr> <tr> <th scope="row"><label for="start_of_week"><?php _e('Week Starts On') ?></label></th> <td><select name="start_of_week" id="start_of_week"> <?php for ($day_index = 0; $day_index <= 6; $day_index++) : $selected = (get_option('start_of_week') == $day_index) ? 'selected="selected"' : ''; echo "\n\t<option value='" . esc_attr($day_index) . "' $selected>" . $wp_locale->get_weekday($day_index) . '</option>'; endfor; ?> </select></td> </tr> <?php do_settings_fields('general', 'default'); ?> <?php $languages = get_available_languages(); if ( is_multisite() && !empty( $languages ) ): ?> <tr valign="top"> <th width="33%" scope="row"><?php _e('Site Language') ?></th> <td> <select name="WPLANG" id="WPLANG"> <?php mu_dropdown_languages( $languages, get_option('WPLANG') ); ?> </select> </td> </tr> <?php endif; ?> </table> <?php do_settings_sections('general'); ?> <?php submit_button(); ?> </form> </div> <?php include('./admin-footer.php') ?>
01happy-blog
trunk/myblog/wp-admin/options-general.php
PHP
oos
13,212
<?php /** * Tools Administration Screen. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); $title = __('Tools'); get_current_screen()->add_help_tab( array( 'id' => 'press-this', 'title' => __('Press This'), 'content' => '<p>' . __('Press This is a bookmarklet that makes it easy to blog about something you come across on the web. You can use it to just grab a link, or to post an excerpt. Press This will even allow you to choose from images included on the page and use them in your post. Just drag the Press This link on this screen to your bookmarks bar in your browser, and you&#8217;ll be on your way to easier content creation. Clicking on it while on another website opens a popup window with all these options.') . '</p>', ) ); get_current_screen()->add_help_tab( array( 'id' => 'converter', 'title' => __('Categories and Tags Converter'), 'content' => '<p>' . __('Categories have hierarchy, meaning that you can nest sub-categories. Tags do not have hierarchy and cannot be nested. Sometimes people start out using one on their posts, then later realize that the other would work better for their content.' ) . '</p>' . '<p>' . __( 'The Categories and Tags Converter link on this screen will take you to the Import screen, where that Converter is one of the plugins you can install. Once that plugin is installed, the Activate Plugin &amp; Run Importer link will take you to a screen where you can choose to convert tags into categories or vice versa.' ) . '</p>', ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Tools_Screen" target="_blank">Documentation on Tools</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); require_once('./admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <?php if ( current_user_can('edit_posts') ) : ?> <div class="tool-box"> <h3 class="title"><?php _e('Press This') ?></h3> <p><?php _e('Press This is a bookmarklet: a little app that runs in your browser and lets you grab bits of the web.');?></p> <p><?php _e('Use Press This to clip text, images and videos from any web page. Then edit and add more straight from Press This before you save or publish it in a post on your site.'); ?></p> <p class="description"><?php _e('Drag-and-drop the following link to your bookmarks bar or right click it and add it to your favorites for a posting shortcut.') ?></p> <p class="pressthis"><a onclick="return false;" oncontextmenu="if(window.navigator.userAgent.indexOf('WebKit')!=-1||window.navigator.userAgent.indexOf('MSIE')!=-1)jQuery('.pressthis-code').show().find('textarea').focus().select();return false;" href="<?php echo htmlspecialchars( get_shortcut_link() ); ?>"><span><?php _e('Press This') ?></span></a></p> <div class="pressthis-code" style="display:none;"> <p class="description"><?php _e('If your bookmarks toolbar is hidden: copy the code below, open your Bookmarks manager, create new bookmark, type Press This into the name field and paste the code into the URL field.') ?></p> <p><textarea rows="5" cols="120" readonly="readonly"><?php echo htmlspecialchars( get_shortcut_link() ); ?></textarea></p> </div> </div> <?php endif; if ( current_user_can( 'import' ) ) : $cats = get_taxonomy('category'); $tags = get_taxonomy('post_tag'); if ( current_user_can($cats->cap->manage_terms) || current_user_can($tags->cap->manage_terms) ) : ?> <div class="tool-box"> <h3 class="title"><?php _e( 'Categories and Tags Converter' ) ?></h3> <p><?php printf( __('If you want to convert your categories to tags (or vice versa), use the <a href="%s">Categories and Tags Converter</a> available from the Import screen.'), 'import.php' ); ?></p> </div> <?php endif; endif; do_action( 'tool_box' ); ?> </div> <?php include('./admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/tools.php
PHP
oos
4,044
<?php /** * Install theme administration panel. * * @package WordPress * @subpackage Administration */ if ( !defined( 'IFRAME_REQUEST' ) && isset( $_GET['tab'] ) && ( 'theme-information' == $_GET['tab'] ) ) define( 'IFRAME_REQUEST', true ); /** WordPress Administration Bootstrap */ require_once('./admin.php'); if ( ! current_user_can('install_themes') ) wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) ); if ( is_multisite() && ! is_network_admin() ) { wp_redirect( network_admin_url( 'theme-install.php' ) ); exit(); } $wp_list_table = _get_list_table('WP_Theme_Install_List_Table'); $pagenum = $wp_list_table->get_pagenum(); $wp_list_table->prepare_items(); $title = __('Install Themes'); $parent_file = 'themes.php'; if ( !is_network_admin() ) $submenu_file = 'themes.php'; wp_enqueue_script( 'theme-install' ); wp_enqueue_script( 'theme' ); $body_id = $tab; do_action('install_themes_pre_' . $tab); //Used to override the general interface, Eg, install or theme information. $help_overview = '<p>' . sprintf(__('You can find additional themes for your site by using the Theme Browser/Installer on this screen, which will display themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. These themes are designed and developed by third parties, are available free of charge, and are compatible with the license WordPress uses.'), 'http://wordpress.org/extend/themes/') . '</p>' . '<p>' . __('You can Search for themes by keyword, author, or tag, or can get more specific and search by criteria listed in the feature filter. Alternately, you can browse the themes that are Featured, Newest, or Recently Updated. When you find a theme you like, you can preview it or install it.') . '</p>' . '<p>' . __('You can Upload a theme manually if you have already downloaded its ZIP archive onto your computer (make sure it is from a trusted and original source). You can also do it the old-fashioned way and copy a downloaded theme&#8217;s folder via FTP into your <code>/wp-content/themes</code> directory.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => $help_overview ) ); $help_installing = '<p>' . __('Once you have generated a list of themes, you can preview and install any of them. Click on the thumbnail of the theme you&#8217;re interested in previewing. It will open up in a full-screen Preview page to give you a better idea of how that theme will look.') . '</p>' . '<p>' . __('To install the theme so you can preview it with your site&#8217;s content and customize its theme options, click the "Install" button at the top of the left-hand pane. The theme files will be downloaded to your website automatically. When this is complete, the theme is now available for activation, which you can do by clicking the "Activate" link, or by navigating to your Installed Themes page and clicking the "Live Preview" link under any installed theme&#8217;s thumbnail image.') . '</p>'; get_current_screen()->add_help_tab( array( 'id' => 'installing', 'title' => __('Previewing and Installing'), 'content' => $help_installing ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes#Adding_New_Themes" target="_blank">Documentation on Adding New Themes</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); include(ABSPATH . 'wp-admin/admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); if ( is_network_admin() ) : ?> <h2><?php echo esc_html( $title ); ?></h2> <?php else : ?> <h2 class="nav-tab-wrapper"><a href="themes.php" class="nav-tab"><?php echo esc_html_x('Manage Themes', 'theme'); ?></a><a href="theme-install.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a></h2> <?php endif; $wp_list_table->views(); ?> <br class="clear" /> <?php do_action('install_themes_' . $tab, $paged); ?> </div> <?php include(ABSPATH . 'wp-admin/admin-footer.php');
01happy-blog
trunk/myblog/wp-admin/theme-install.php
PHP
oos
4,147
<?php /** * Edit plugin editor administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); if ( is_multisite() && ! is_network_admin() ) { wp_redirect( network_admin_url( 'plugin-editor.php' ) ); exit(); } if ( !current_user_can('edit_plugins') ) wp_die( __('You do not have sufficient permissions to edit plugins for this site.') ); $title = __("Edit Plugins"); $parent_file = 'plugins.php'; wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin')); $plugins = get_plugins(); if ( empty($plugins) ) wp_die( __('There are no plugins installed on this site.') ); if ( isset($_REQUEST['file']) ) $plugin = stripslashes($_REQUEST['file']); if ( empty($plugin) ) { $plugin = array_keys($plugins); $plugin = $plugin[0]; } $plugin_files = get_plugin_files($plugin); if ( empty($file) ) $file = $plugin_files[0]; else $file = stripslashes($file); $file = validate_file_to_edit($file, $plugin_files); $real_file = WP_PLUGIN_DIR . '/' . $file; $scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0; switch ( $action ) { case 'update': check_admin_referer('edit-plugin_' . $file); $newcontent = stripslashes($_POST['newcontent']); if ( is_writeable($real_file) ) { $f = fopen($real_file, 'w+'); fwrite($f, $newcontent); fclose($f); $network_wide = is_plugin_active_for_network( $file ); // Deactivate so we can test it. if ( is_plugin_active($file) || isset($_POST['phperror']) ) { if ( is_plugin_active($file) ) deactivate_plugins($file, true); if ( ! is_network_admin() ) update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) ); wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide)); exit; } wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); } else { wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") ); } exit; break; default: if ( isset($_GET['liveupdate']) ) { check_admin_referer('edit-plugin-test_' . $file); $error = validate_plugin($file); if ( is_wp_error($error) ) wp_die( $error ); if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) ) activate_plugin($file, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) ); // we'll override this later if the plugin can be included without fatal error wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); exit; } // List of allowable extensions $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include'); $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions); if ( ! is_file($real_file) ) { wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.'))); } else { // Get the extension of the file if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) { $ext = strtolower($matches[1]); // If extension is not in the acceptable list, skip it if ( !in_array( $ext, $editable_extensions) ) wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.'))); } } get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('You can use the editor to make changes to any of your plugins&#8217; individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.') . '</p>' . '<p>' . __('Choose a plugin to edit from the menu in the upper right and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don&#8217;t forget to save your changes (Update File) when you&#8217;re finished.') . '</p>' . '<p>' . __('The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Lookup takes you to a web page about that particular function.') . '</p>' . '<p>' . __('If you want to make changes but don&#8217;t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.') . '</p>' . ( is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>' : '' ) ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Plugins_Editor_Screen" target="_blank">Documentation on Editing Plugins</a>') . '</p>' . '<p>' . __('<a href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">Documentation on Writing Plugins</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); require_once(ABSPATH . 'wp-admin/admin-header.php'); update_recently_edited(WP_PLUGIN_DIR . '/' . $file); $content = file_get_contents( $real_file ); if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) { $functions = wp_doc_link_parse( $content ); if ( !empty($functions) ) { $docs_select = '<select name="docs-list" id="docs-list">'; $docs_select .= '<option value="">' . __( 'Function Name&hellip;' ) . '</option>'; foreach ( $functions as $function) { $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>'; } $docs_select .= '</select>'; } } $content = esc_textarea( $content ); ?> <?php if (isset($_GET['a'])) : ?> <div id="message" class="updated"><p><?php _e('File edited successfully.') ?></p></div> <?php elseif (isset($_GET['phperror'])) : ?> <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p> <?php if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?> <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo esc_attr($file); ?>&amp;_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe> <?php } ?> </div> <?php endif; ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <div class="fileedit-sub"> <div class="alignleft"> <big><?php if ( is_plugin_active($plugin) ) { if ( is_writeable($real_file) ) echo sprintf(__('Editing <strong>%s</strong> (active)'), $file); else echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file); } else { if ( is_writeable($real_file) ) echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file); else echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file); } ?></big> </div> <div class="alignright"> <form action="plugin-editor.php" method="post"> <strong><label for="plugin"><?php _e('Select plugin to edit:'); ?> </label></strong> <select name="plugin" id="plugin"> <?php foreach ( $plugins as $plugin_key => $a_plugin ) { $plugin_name = $a_plugin['Name']; if ( $plugin_key == $plugin ) $selected = " selected='selected'"; else $selected = ''; $plugin_name = esc_attr($plugin_name); $plugin_key = esc_attr($plugin_key); echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>"; } ?> </select> <?php submit_button( __( 'Select' ), 'button', 'Submit', false ); ?> </form> </div> <br class="clear" /> </div> <div id="templateside"> <h3><?php _e('Plugin Files'); ?></h3> <ul> <?php foreach ( $plugin_files as $plugin_file ) : // Get the extension of the file if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) { $ext = strtolower($matches[1]); // If extension is not in the acceptable list, skip it if ( !in_array( $ext, $editable_extensions ) ) continue; } else { // No extension found continue; } ?> <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo urlencode( $plugin_file ) ?>&amp;plugin=<?php echo urlencode( $plugin ) ?>"><?php echo $plugin_file ?></a></li> <?php endforeach; ?> </ul> </div> <form name="template" id="template" action="plugin-editor.php" method="post"> <?php wp_nonce_field('edit-plugin_' . $file) ?> <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> <input type="hidden" name="action" value="update" /> <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" /> <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" /> <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> </div> <?php if ( !empty( $docs_select ) ) : ?> <div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php echo urlencode( get_locale() ) ?>&amp;version=<?php echo urlencode( $wp_version ) ?>&amp;redirect=true'); }" /></div> <?php endif; ?> <?php if ( is_writeable($real_file) ) : ?> <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?> <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p> <?php } ?> <p class="submit"> <?php if ( isset($_GET['phperror']) ) { echo "<input type='hidden' name='phperror' value='1' />"; submit_button( __( 'Update File and Attempt to Reactivate' ), 'primary', 'submit', false, array( 'tabindex' => '2' ) ); } else { submit_button( __( 'Update File' ), 'primary', 'submit', false, array( 'tabindex' => '2' ) ); } ?> </p> <?php else : ?> <p><em><?php _e('You need to make this file writable before you can save your changes. See <a href="http://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p> <?php endif; ?> </form> <br class="clear" /> </div> <script type="text/javascript"> /* <![CDATA[ */ jQuery(document).ready(function($){ $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); }); $('#newcontent').scrollTop( $('#scrollto').val() ); }); /* ]]> */ </script> <?php break; } include(ABSPATH . "wp-admin/admin-footer.php");
01happy-blog
trunk/myblog/wp-admin/plugin-editor.php
PHP
oos
10,924
<?php /** * WordPress Administration Bootstrap * * @package WordPress * @subpackage Administration */ /** * In WordPress Administration Screens * * @since 2.3.2 */ if ( ! defined('WP_ADMIN') ) define('WP_ADMIN', true); if ( ! defined('WP_NETWORK_ADMIN') ) define('WP_NETWORK_ADMIN', false); if ( ! defined('WP_USER_ADMIN') ) define('WP_USER_ADMIN', false); if ( ! WP_NETWORK_ADMIN && ! WP_USER_ADMIN ) { define('WP_BLOG_ADMIN', true); } if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') ) define('WP_LOAD_IMPORTERS', true); require_once(dirname(dirname(__FILE__)) . '/wp-load.php'); if ( get_option('db_upgraded') ) { flush_rewrite_rules(); update_option( 'db_upgraded', false ); /** * Runs on the next page load after successful upgrade * * @since 2.8 */ do_action('after_db_upgrade'); } elseif ( get_option('db_version') != $wp_db_version && empty($_POST) ) { if ( !is_multisite() ) { wp_redirect(admin_url('upgrade.php?_wp_http_referer=' . urlencode(stripslashes($_SERVER['REQUEST_URI'])))); exit; } elseif ( apply_filters( 'do_mu_upgrade', true ) ) { /** * On really small MU installs run the upgrader every time, * else run it less often to reduce load. * * @since 2.8.4b */ $c = get_blog_count(); if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) { require_once( ABSPATH . WPINC . '/http.php' ); $response = wp_remote_get( admin_url( 'upgrade.php?step=1' ), array( 'timeout' => 120, 'httpversion' => '1.1' ) ); do_action( 'after_mu_upgrade', $response ); unset($response); } unset($c); } } require_once(ABSPATH . 'wp-admin/includes/admin.php'); auth_redirect(); nocache_headers(); // Schedule trash collection if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') ) wp_schedule_event(time(), 'daily', 'wp_scheduled_delete'); set_screen_options(); $date_format = get_option('date_format'); $time_format = get_option('time_format'); wp_reset_vars(array('profile', 'redirect', 'redirect_url', 'a', 'text', 'trackback', 'pingback')); wp_enqueue_script( 'common' ); wp_enqueue_script( 'jquery-color' ); $editing = false; if ( isset($_GET['page']) ) { $plugin_page = stripslashes($_GET['page']); $plugin_page = plugin_basename($plugin_page); } if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) $typenow = $_REQUEST['post_type']; else $typenow = ''; if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) $taxnow = $_REQUEST['taxonomy']; else $taxnow = ''; if ( WP_NETWORK_ADMIN ) require(ABSPATH . 'wp-admin/network/menu.php'); elseif ( WP_USER_ADMIN ) require(ABSPATH . 'wp-admin/user/menu.php'); else require(ABSPATH . 'wp-admin/menu.php'); if ( current_user_can( 'manage_options' ) ) @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); do_action('admin_init'); if ( isset($plugin_page) ) { if ( !empty($typenow) ) $the_parent = $pagenow . '?post_type=' . $typenow; else $the_parent = $pagenow; if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) { $page_hook = get_plugin_page_hook($plugin_page, $plugin_page); // backwards compatibility for plugins using add_management_page if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook($plugin_page, 'tools.php') ) { // There could be plugin specific params on the URL, so we need the whole query string if ( !empty($_SERVER[ 'QUERY_STRING' ]) ) $query_string = $_SERVER[ 'QUERY_STRING' ]; else $query_string = 'page=' . $plugin_page; wp_redirect( admin_url('tools.php?' . $query_string) ); exit; } } unset($the_parent); } $hook_suffix = ''; if ( isset($page_hook) ) $hook_suffix = $page_hook; else if ( isset($plugin_page) ) $hook_suffix = $plugin_page; else if ( isset($pagenow) ) $hook_suffix = $pagenow; set_current_screen(); // Handle plugin admin pages. if ( isset($plugin_page) ) { if ( $page_hook ) { do_action('load-' . $page_hook); if (! isset($_GET['noheader'])) require_once(ABSPATH . 'wp-admin/admin-header.php'); do_action($page_hook); } else { if ( validate_file($plugin_page) ) wp_die(__('Invalid plugin page')); if ( !( file_exists(WP_PLUGIN_DIR . "/$plugin_page") && is_file(WP_PLUGIN_DIR . "/$plugin_page") ) && !( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") && is_file(WPMU_PLUGIN_DIR . "/$plugin_page") ) ) wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page))); do_action('load-' . $plugin_page); if ( !isset($_GET['noheader'])) require_once(ABSPATH . 'wp-admin/admin-header.php'); if ( file_exists(WPMU_PLUGIN_DIR . "/$plugin_page") ) include(WPMU_PLUGIN_DIR . "/$plugin_page"); else include(WP_PLUGIN_DIR . "/$plugin_page"); } include(ABSPATH . 'wp-admin/admin-footer.php'); exit(); } else if (isset($_GET['import'])) { $importer = $_GET['import']; if ( ! current_user_can('import') ) wp_die(__('You are not allowed to import.')); if ( validate_file($importer) ) { wp_redirect( admin_url( 'import.php?invalid=' . $importer ) ); exit; } if ( ! isset($wp_importers[$importer]) || ! is_callable($wp_importers[$importer][2]) ) { wp_redirect( admin_url( 'import.php?invalid=' . $importer ) ); exit; } $parent_file = 'tools.php'; $submenu_file = 'import.php'; $title = __('Import'); if (! isset($_GET['noheader'])) require_once(ABSPATH . 'wp-admin/admin-header.php'); require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); define('WP_IMPORTING', true); if ( apply_filters( 'force_filtered_html_on_import', false ) ) kses_init_filters(); // Always filter imported data with kses on multisite. call_user_func($wp_importers[$importer][2]); include(ABSPATH . 'wp-admin/admin-footer.php'); // Make sure rules are flushed flush_rewrite_rules(false); exit(); } else { do_action("load-$pagenow"); // Backwards compatibility with old load-page-new.php, load-page.php, // and load-categories.php actions. if ( $typenow == 'page' ) { if ( $pagenow == 'post-new.php' ) do_action( 'load-page-new.php' ); elseif ( $pagenow == 'post.php' ) do_action( 'load-page.php' ); } elseif ( $pagenow == 'edit-tags.php' ) { if ( $taxnow == 'category' ) do_action( 'load-categories.php' ); elseif ( $taxnow == 'link_category' ) do_action( 'load-edit-link-categories.php' ); } } if ( !empty($_REQUEST['action']) ) do_action('admin_action_' . $_REQUEST['action']);
01happy-blog
trunk/myblog/wp-admin/admin.php
PHP
oos
6,489
<?php /** * Writing settings administration panel. * * @package WordPress * @subpackage Administration */ /** WordPress Administration Bootstrap */ require_once('./admin.php'); if ( ! current_user_can( 'manage_options' ) ) wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) ); $title = __('Writing Settings'); $parent_file = 'options-general.php'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('You can submit content in several different ways; this screen holds the settings for all of them. The top section controls the editor within the dashboard, while the rest control external publishing methods. For more information on any of these methods, use the documentation links.') . '</p>' . '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>', ) ); get_current_screen()->add_help_tab( array( 'id' => 'options-press', 'title' => __('Press This'), 'content' => '<p>' . __('Press This is a bookmarklet that makes it easy to blog about something you come across on the web. You can use it to just grab a link, or to post an excerpt. Press This will even allow you to choose from images included on the page and use them in your post. Just drag the Press This link on this screen to your bookmarks bar in your browser, and you&#8217;ll be on your way to easier content creation. Clicking on it while on another website opens a popup window with all these options.') . '</p>', ) ); if ( is_multisite() ) { $post_email_help = '<p>' . __('Due to security issues, you cannot use Post By Email on Multisite Installs.') . '</p>'; } else { $post_email_help = '<p>' . __('Post via email settings allow you to send your WordPress install an email with the content of your post. You must set up a secret e-mail account with POP3 access to use this, and any mail received at this address will be posted, so it&#8217;s a good idea to keep this address very secret.') . '</p>'; } get_current_screen()->add_help_tab( array( 'id' => 'options-postemail', 'title' => __('Post Via Email'), 'content' => $post_email_help, ) ); get_current_screen()->add_help_tab( array( 'id' => 'options-remote', 'title' => __('Remote Publishing'), 'content' => '<p>' . __('Remote Publishing allows you to use an external editor (like the iOS or Android app) to write your posts.') . '</p>', ) ); get_current_screen()->add_help_tab( array( 'id' => 'options-services', 'title' => __('Update Services'), 'content' => '<p>' . __('If desired, WordPress will automatically alert various services of your new posts.') . '</p>', ) ); get_current_screen()->set_help_sidebar( '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Settings_Writing_Screen" target="_blank">Documentation on Writing Settings</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ); include('./admin-header.php'); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo esc_html( $title ); ?></h2> <form method="post" action="options.php"> <?php settings_fields('writing'); ?> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="default_post_edit_rows"> <?php _e('Size of the post box') ?></label></th> <td><input name="default_post_edit_rows" type="text" id="default_post_edit_rows" value="<?php form_option('default_post_edit_rows'); ?>" class="small-text" /> <?php _e('lines') ?></td> </tr> <tr valign="top"> <th scope="row"><?php _e('Formatting') ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php _e('Formatting') ?></span></legend> <label for="use_smilies"> <input name="use_smilies" type="checkbox" id="use_smilies" value="1" <?php checked('1', get_option('use_smilies')); ?> /> <?php _e('Convert emoticons like <code>:-)</code> and <code>:-P</code> to graphics on display') ?></label><br /> <label for="use_balanceTags"><input name="use_balanceTags" type="checkbox" id="use_balanceTags" value="1" <?php checked('1', get_option('use_balanceTags')); ?> /> <?php _e('WordPress should correct invalidly nested XHTML automatically') ?></label> </fieldset></td> </tr> <tr valign="top"> <th scope="row"><label for="default_category"><?php _e('Default Post Category') ?></label></th> <td> <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'default_category', 'orderby' => 'name', 'selected' => get_option('default_category'), 'hierarchical' => true)); ?> </td> </tr> <?php if ( current_theme_supports( 'post-formats' ) ) : $post_formats = get_theme_support( 'post-formats' ); if ( is_array( $post_formats[0] ) ) : ?> <tr valign="top"> <th scope="row"><label for="default_post_format"><?php _e('Default Post Format') ?></label></th> <td> <select name="default_post_format" id="default_post_format"> <option value="0"><?php _e('Standard'); ?></option> <?php foreach ( $post_formats[0] as $format ): ?> <option<?php selected( get_option('default_post_format'), $format ); ?> value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option> <?php endforeach; ?> </select> </td> </tr> <?php endif; endif; ?> <tr valign="top"> <th scope="row"><label for="default_link_category"><?php _e('Default Link Category') ?></label></th> <td> <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'default_link_category', 'orderby' => 'name', 'selected' => get_option('default_link_category'), 'hierarchical' => true, 'taxonomy' => 'link_category')); ?> </td> </tr> <?php do_settings_fields('writing', 'default'); ?> </table> <h3 class="title"><?php _e('Press This') ?></h3> <p><?php _e('Press This is a bookmarklet: a little app that runs in your browser and lets you grab bits of the web.');?></p> <p><?php _e('Use Press This to clip text, images and videos from any web page. Then edit and add more straight from Press This before you save or publish it in a post on your site.'); ?></p> <p><?php _e('Drag-and-drop the following link to your bookmarks bar or right click it and add it to your favorites for a posting shortcut.') ?></p> <p class="pressthis"><a onclick="return false;" oncontextmenu="if(window.navigator.userAgent.indexOf('WebKit')!=-1||window.navigator.userAgent.indexOf('MSIE')!=-1)jQuery('.pressthis-code').show().find('textarea').focus().select();return false;" href="<?php echo htmlspecialchars( get_shortcut_link() ); ?>"><span><?php _e('Press This') ?></span></a></p> <div class="pressthis-code" style="display:none;"> <p class="description"><?php _e('If your bookmarks toolbar is hidden: copy the code below, open your Bookmarks manager, create new bookmark, type Press This into the name field and paste the code into the URL field.') ?></p> <p><textarea rows="5" cols="120" readonly="readonly"><?php echo htmlspecialchars( get_shortcut_link() ); ?></textarea></p> </div> <?php if ( apply_filters( 'enable_post_by_email_configuration', true ) ) { ?> <h3><?php _e('Post via e-mail') ?></h3> <p><?php printf(__('To post to WordPress by e-mail you must set up a secret e-mail account with POP3 access. Any mail received at this address will be posted, so it&#8217;s a good idea to keep this address very secret. Here are three random strings you could use: <kbd>%s</kbd>, <kbd>%s</kbd>, <kbd>%s</kbd>.'), wp_generate_password(8, false), wp_generate_password(8, false), wp_generate_password(8, false)) ?></p> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="mailserver_url"><?php _e('Mail Server') ?></label></th> <td><input name="mailserver_url" type="text" id="mailserver_url" value="<?php form_option('mailserver_url'); ?>" class="regular-text code" /> <label for="mailserver_port"><?php _e('Port') ?></label> <input name="mailserver_port" type="text" id="mailserver_port" value="<?php form_option('mailserver_port'); ?>" class="small-text" /> </td> </tr> <tr valign="top"> <th scope="row"><label for="mailserver_login"><?php _e('Login Name') ?></label></th> <td><input name="mailserver_login" type="text" id="mailserver_login" value="<?php form_option('mailserver_login'); ?>" class="regular-text ltr" /></td> </tr> <tr valign="top"> <th scope="row"><label for="mailserver_pass"><?php _e('Password') ?></label></th> <td> <input name="mailserver_pass" type="text" id="mailserver_pass" value="<?php form_option('mailserver_pass'); ?>" class="regular-text ltr" /> </td> </tr> <tr valign="top"> <th scope="row"><label for="default_email_category"><?php _e('Default Mail Category') ?></label></th> <td> <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'default_email_category', 'orderby' => 'name', 'selected' => get_option('default_email_category'), 'hierarchical' => true)); ?> </td> </tr> <?php do_settings_fields('writing', 'post_via_email'); ?> </table> <?php } ?> <h3><?php _e('Remote Publishing') ?></h3> <p><?php printf(__('To post to WordPress from a desktop blogging client or remote website that uses the Atom Publishing Protocol or one of the XML-RPC publishing interfaces you must enable them below.')) ?></p> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Atom Publishing Protocol') ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php _e('Atom Publishing Protocol') ?></span></legend> <label for="enable_app"> <input name="enable_app" type="checkbox" id="enable_app" value="1" <?php checked('1', get_option('enable_app')); ?> /> <?php _e('Enable the Atom Publishing Protocol.') ?></label><br /> </fieldset></td> </tr> <tr valign="top"> <th scope="row"><?php _e('XML-RPC') ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php _e('XML-RPC') ?></span></legend> <label for="enable_xmlrpc"> <input name="enable_xmlrpc" type="checkbox" id="enable_xmlrpc" value="1" <?php checked('1', get_option('enable_xmlrpc')); ?> /> <?php _e('Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols.') ?></label><br /> </fieldset></td> </tr> <?php do_settings_fields('writing', 'remote_publishing'); ?> </table> <?php if ( apply_filters( 'enable_update_services_configuration', true ) ) { ?> <h3><?php _e('Update Services') ?></h3> <?php if ( 1 == get_option('blog_public') ) : ?> <p><label for="ping_sites"><?php _e('When you publish a new post, WordPress automatically notifies the following site update services. For more about this, see <a href="http://codex.wordpress.org/Update_Services">Update Services</a> on the Codex. Separate multiple service <abbr title="Universal Resource Locator">URL</abbr>s with line breaks.') ?></label></p> <textarea name="ping_sites" id="ping_sites" class="large-text code" rows="3"><?php echo esc_textarea( get_option('ping_sites') ); ?></textarea> <?php else : ?> <p><?php printf(__('WordPress is not notifying any <a href="http://codex.wordpress.org/Update_Services">Update Services</a> because of your site&#8217;s <a href="%s">privacy settings</a>.'), 'options-privacy.php'); ?></p> <?php endif; ?> <?php } // multisite ?> <?php do_settings_sections('writing'); ?> <?php submit_button(); ?> </form> </div> <?php include('./admin-footer.php') ?>
01happy-blog
trunk/myblog/wp-admin/options-writing.php
PHP
oos
11,257
<?php // -------------------------------------------------------------------------------- // PhpConcept Library - Zip Module 2.8.2 // -------------------------------------------------------------------------------- // License GNU/LGPL - Vincent Blavet - August 2009 // http://www.phpconcept.net // -------------------------------------------------------------------------------- // // Presentation : // PclZip is a PHP library that manage ZIP archives. // So far tests show that archives generated by PclZip are readable by // WinZip application and other tools. // // Description : // See readme.txt and http://www.phpconcept.net // // Warning : // This library and the associated files are non commercial, non professional // work. // It should not have unexpected results. However if any damage is caused by // this software the author can not be responsible. // The use of this software is at the risk of the user. // // -------------------------------------------------------------------------------- // $Id: pclzip.lib.php,v 1.60 2009/09/30 21:01:04 vblavet Exp $ // -------------------------------------------------------------------------------- // ----- Constants if (!defined('PCLZIP_READ_BLOCK_SIZE')) { define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); } // ----- File list separator // In version 1.x of PclZip, the separator for file list is a space // (which is not a very smart choice, specifically for windows paths !). // A better separator should be a comma (,). This constant gives you the // abilty to change that. // However notice that changing this value, may have impact on existing // scripts, using space separated filenames. // Recommanded values for compatibility with older versions : //define( 'PCLZIP_SEPARATOR', ' ' ); // Recommanded values for smart separation of filenames. if (!defined('PCLZIP_SEPARATOR')) { define( 'PCLZIP_SEPARATOR', ',' ); } // ----- Error configuration // 0 : PclZip Class integrated error handling // 1 : PclError external library error handling. By enabling this // you must ensure that you have included PclError library. // [2,...] : reserved for futur use if (!defined('PCLZIP_ERROR_EXTERNAL')) { define( 'PCLZIP_ERROR_EXTERNAL', 0 ); } // ----- Optional static temporary directory // By default temporary files are generated in the script current // path. // If defined : // - MUST BE terminated by a '/'. // - MUST be a valid, already created directory // Samples : // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); if (!defined('PCLZIP_TEMPORARY_DIR')) { define( 'PCLZIP_TEMPORARY_DIR', '' ); } // ----- Optional threshold ratio for use of temporary files // Pclzip sense the size of the file to add/extract and decide to // use or not temporary file. The algorythm is looking for // memory_limit of PHP and apply a ratio. // threshold = memory_limit * ratio. // Recommended values are under 0.5. Default 0.47. // Samples : // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); } // -------------------------------------------------------------------------------- // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED ***** // -------------------------------------------------------------------------------- // ----- Global variables $g_pclzip_version = "2.8.2"; // ----- Error codes // -1 : Unable to open file in binary write mode // -2 : Unable to open file in binary read mode // -3 : Invalid parameters // -4 : File does not exist // -5 : Filename is too long (max. 255) // -6 : Not a valid zip file // -7 : Invalid extracted file size // -8 : Unable to create directory // -9 : Invalid archive extension // -10 : Invalid archive format // -11 : Unable to delete file (unlink) // -12 : Unable to rename file (rename) // -13 : Invalid header checksum // -14 : Invalid archive size define( 'PCLZIP_ERR_USER_ABORTED', 2 ); define( 'PCLZIP_ERR_NO_ERROR', 0 ); define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); define( 'PCLZIP_ERR_MISSING_FILE', -4 ); define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); // ----- Options values define( 'PCLZIP_OPT_PATH', 77001 ); define( 'PCLZIP_OPT_ADD_PATH', 77002 ); define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); define( 'PCLZIP_OPT_BY_NAME', 77008 ); define( 'PCLZIP_OPT_BY_INDEX', 77009 ); define( 'PCLZIP_OPT_BY_EREG', 77010 ); define( 'PCLZIP_OPT_BY_PREG', 77011 ); define( 'PCLZIP_OPT_COMMENT', 77012 ); define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); // Having big trouble with crypt. Need to multiply 2 long int // which is not correctly supported by PHP ... //define( 'PCLZIP_OPT_CRYPT', 77018 ); define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 ); define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 ); define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 ); define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias // ----- File description attributes define( 'PCLZIP_ATT_FILE_NAME', 79001 ); define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); // ----- Call backs values define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); define( 'PCLZIP_CB_PRE_ADD', 78003 ); define( 'PCLZIP_CB_POST_ADD', 78004 ); /* For futur use define( 'PCLZIP_CB_PRE_LIST', 78005 ); define( 'PCLZIP_CB_POST_LIST', 78006 ); define( 'PCLZIP_CB_PRE_DELETE', 78007 ); define( 'PCLZIP_CB_POST_DELETE', 78008 ); */ // -------------------------------------------------------------------------------- // Class : PclZip // Description : // PclZip is the class that represent a Zip archive. // The public methods allow the manipulation of the archive. // Attributes : // Attributes must not be accessed directly. // Methods : // PclZip() : Object creator // create() : Creates the Zip archive // listContent() : List the content of the Zip archive // extract() : Extract the content of the archive // properties() : List the properties of the archive // -------------------------------------------------------------------------------- class PclZip { // ----- Filename of the zip file var $zipname = ''; // ----- File descriptor of the zip file var $zip_fd = 0; // ----- Internal error handling var $error_code = 1; var $error_string = ''; // ----- Current status of the magic_quotes_runtime // This value store the php configuration for magic_quotes // The class can then disable the magic_quotes and reset it after var $magic_quotes_status; // -------------------------------------------------------------------------------- // Function : PclZip() // Description : // Creates a PclZip object and set the name of the associated Zip archive // filename. // Note that no real action is taken, if the archive does not exist it is not // created. Use create() for that. // -------------------------------------------------------------------------------- function PclZip($p_zipname) { // ----- Tests the zlib if (!function_exists('gzopen')) { die('Abort '.basename(__FILE__).' : Missing zlib extensions'); } // ----- Set the attributes $this->zipname = $p_zipname; $this->zip_fd = 0; $this->magic_quotes_status = -1; // ----- Return return; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : // create($p_filelist, $p_add_dir="", $p_remove_dir="") // create($p_filelist, $p_option, $p_option_value, ...) // Description : // This method supports two different synopsis. The first one is historical. // This method creates a Zip Archive. The Zip file is created in the // filesystem. The files and directories indicated in $p_filelist // are added in the archive. See the parameters description for the // supported format of $p_filelist. // When a directory is in the list, the directory and its content is added // in the archive. // In this synopsis, the function takes an optional variable list of // options. See bellow the supported options. // Parameters : // $p_filelist : An array containing file or directory names, or // a string containing one filename or one directory name, or // a string containing a list of filenames and/or directory // names separated by spaces. // $p_add_dir : A path to add before the real path of the archived file, // in order to have it memorized in the archive. // $p_remove_dir : A path to remove from the real path of the file to archive, // in order to have a shorter path memorized in the archive. // When $p_add_dir and $p_remove_dir are set, $p_remove_dir // is removed first, before $p_add_dir is added. // Options : // PCLZIP_OPT_ADD_PATH : // PCLZIP_OPT_REMOVE_PATH : // PCLZIP_OPT_REMOVE_ALL_PATH : // PCLZIP_OPT_COMMENT : // PCLZIP_CB_PRE_ADD : // PCLZIP_CB_POST_ADD : // Return Values : // 0 on failure, // The list of the added files, with a status of the add action. // (see PclZip::listContent() for list entry format) // -------------------------------------------------------------------------------- function create($p_filelist) { $v_result=1; // ----- Reset the error handler $this->privErrorReset(); // ----- Set default values $v_options = array(); $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; // ----- Look for variable options arguments $v_size = func_num_args(); // ----- Look for arguments if ($v_size > 1) { // ----- Get the arguments $v_arg_list = func_get_args(); // ----- Remove from the options list the first argument array_shift($v_arg_list); $v_size--; // ----- Look for first arg if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_REMOVE_PATH => 'optional', PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', PCLZIP_OPT_ADD_PATH => 'optional', PCLZIP_CB_PRE_ADD => 'optional', PCLZIP_CB_POST_ADD => 'optional', PCLZIP_OPT_NO_COMPRESSION => 'optional', PCLZIP_OPT_COMMENT => 'optional', PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', PCLZIP_OPT_TEMP_FILE_ON => 'optional', PCLZIP_OPT_TEMP_FILE_OFF => 'optional' //, PCLZIP_OPT_CRYPT => 'optional' )); if ($v_result != 1) { return 0; } } // ----- Look for 2 args // Here we need to support the first historic synopsis of the // method. else { // ----- Get the first argument $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; // ----- Look for the optional second argument if ($v_size == 2) { $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; } else if ($v_size > 2) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); return 0; } } } // ----- Look for default option values $this->privOptionDefaultThreshold($v_options); // ----- Init $v_string_list = array(); $v_att_list = array(); $v_filedescr_list = array(); $p_result_list = array(); // ----- Look if the $p_filelist is really an array if (is_array($p_filelist)) { // ----- Look if the first element is also an array // This will mean that this is a file description entry if (isset($p_filelist[0]) && is_array($p_filelist[0])) { $v_att_list = $p_filelist; } // ----- The list is a list of string names else { $v_string_list = $p_filelist; } } // ----- Look if the $p_filelist is a string else if (is_string($p_filelist)) { // ----- Create a list from the string $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); } // ----- Invalid variable type for $p_filelist else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); return 0; } // ----- Reformat the string list if (sizeof($v_string_list) != 0) { foreach ($v_string_list as $v_string) { if ($v_string != '') { $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; } else { } } } // ----- For each file in the list check the attributes $v_supported_attributes = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' ,PCLZIP_ATT_FILE_MTIME => 'optional' ,PCLZIP_ATT_FILE_CONTENT => 'optional' ,PCLZIP_ATT_FILE_COMMENT => 'optional' ); foreach ($v_att_list as $v_entry) { $v_result = $this->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes); if ($v_result != 1) { return 0; } } // ----- Expand the filelist (expand directories) $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); if ($v_result != 1) { return 0; } // ----- Call the create fct $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); if ($v_result != 1) { return 0; } // ----- Return return $p_result_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : // add($p_filelist, $p_add_dir="", $p_remove_dir="") // add($p_filelist, $p_option, $p_option_value, ...) // Description : // This method supports two synopsis. The first one is historical. // This methods add the list of files in an existing archive. // If a file with the same name already exists, it is added at the end of the // archive, the first one is still present. // If the archive does not exist, it is created. // Parameters : // $p_filelist : An array containing file or directory names, or // a string containing one filename or one directory name, or // a string containing a list of filenames and/or directory // names separated by spaces. // $p_add_dir : A path to add before the real path of the archived file, // in order to have it memorized in the archive. // $p_remove_dir : A path to remove from the real path of the file to archive, // in order to have a shorter path memorized in the archive. // When $p_add_dir and $p_remove_dir are set, $p_remove_dir // is removed first, before $p_add_dir is added. // Options : // PCLZIP_OPT_ADD_PATH : // PCLZIP_OPT_REMOVE_PATH : // PCLZIP_OPT_REMOVE_ALL_PATH : // PCLZIP_OPT_COMMENT : // PCLZIP_OPT_ADD_COMMENT : // PCLZIP_OPT_PREPEND_COMMENT : // PCLZIP_CB_PRE_ADD : // PCLZIP_CB_POST_ADD : // Return Values : // 0 on failure, // The list of the added files, with a status of the add action. // (see PclZip::listContent() for list entry format) // -------------------------------------------------------------------------------- function add($p_filelist) { $v_result=1; // ----- Reset the error handler $this->privErrorReset(); // ----- Set default values $v_options = array(); $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; // ----- Look for variable options arguments $v_size = func_num_args(); // ----- Look for arguments if ($v_size > 1) { // ----- Get the arguments $v_arg_list = func_get_args(); // ----- Remove form the options list the first argument array_shift($v_arg_list); $v_size--; // ----- Look for first arg if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_REMOVE_PATH => 'optional', PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', PCLZIP_OPT_ADD_PATH => 'optional', PCLZIP_CB_PRE_ADD => 'optional', PCLZIP_CB_POST_ADD => 'optional', PCLZIP_OPT_NO_COMPRESSION => 'optional', PCLZIP_OPT_COMMENT => 'optional', PCLZIP_OPT_ADD_COMMENT => 'optional', PCLZIP_OPT_PREPEND_COMMENT => 'optional', PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', PCLZIP_OPT_TEMP_FILE_ON => 'optional', PCLZIP_OPT_TEMP_FILE_OFF => 'optional' //, PCLZIP_OPT_CRYPT => 'optional' )); if ($v_result != 1) { return 0; } } // ----- Look for 2 args // Here we need to support the first historic synopsis of the // method. else { // ----- Get the first argument $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; // ----- Look for the optional second argument if ($v_size == 2) { $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; } else if ($v_size > 2) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); // ----- Return return 0; } } } // ----- Look for default option values $this->privOptionDefaultThreshold($v_options); // ----- Init $v_string_list = array(); $v_att_list = array(); $v_filedescr_list = array(); $p_result_list = array(); // ----- Look if the $p_filelist is really an array if (is_array($p_filelist)) { // ----- Look if the first element is also an array // This will mean that this is a file description entry if (isset($p_filelist[0]) && is_array($p_filelist[0])) { $v_att_list = $p_filelist; } // ----- The list is a list of string names else { $v_string_list = $p_filelist; } } // ----- Look if the $p_filelist is a string else if (is_string($p_filelist)) { // ----- Create a list from the string $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); } // ----- Invalid variable type for $p_filelist else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); return 0; } // ----- Reformat the string list if (sizeof($v_string_list) != 0) { foreach ($v_string_list as $v_string) { $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; } } // ----- For each file in the list check the attributes $v_supported_attributes = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' ,PCLZIP_ATT_FILE_MTIME => 'optional' ,PCLZIP_ATT_FILE_CONTENT => 'optional' ,PCLZIP_ATT_FILE_COMMENT => 'optional' ); foreach ($v_att_list as $v_entry) { $v_result = $this->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes); if ($v_result != 1) { return 0; } } // ----- Expand the filelist (expand directories) $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); if ($v_result != 1) { return 0; } // ----- Call the create fct $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); if ($v_result != 1) { return 0; } // ----- Return return $p_result_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : listContent() // Description : // This public method, gives the list of the files and directories, with their // properties. // The properties of each entries in the list are (used also in other functions) : // filename : Name of the file. For a create or add action it is the filename // given by the user. For an extract function it is the filename // of the extracted file. // stored_filename : Name of the file / directory stored in the archive. // size : Size of the stored file. // compressed_size : Size of the file's data compressed in the archive // (without the headers overhead) // mtime : Last known modification date of the file (UNIX timestamp) // comment : Comment associated with the file // folder : true | false // index : index of the file in the archive // status : status of the action (depending of the action) : // Values are : // ok : OK ! // filtered : the file / dir is not extracted (filtered by user) // already_a_directory : the file can not be extracted because a // directory with the same name already exists // write_protected : the file can not be extracted because a file // with the same name already exists and is // write protected // newer_exist : the file was not extracted because a newer file exists // path_creation_fail : the file is not extracted because the folder // does not exist and can not be created // write_error : the file was not extracted because there was a // error while writing the file // read_error : the file was not extracted because there was a error // while reading the file // invalid_header : the file was not extracted because of an archive // format error (bad file header) // Note that each time a method can continue operating when there // is an action error on a file, the error is only logged in the file status. // Return Values : // 0 on an unrecoverable failure, // The list of the files in the archive. // -------------------------------------------------------------------------------- function listContent() { $v_result=1; // ----- Reset the error handler $this->privErrorReset(); // ----- Check archive if (!$this->privCheckFormat()) { return(0); } // ----- Call the extracting fct $p_list = array(); if (($v_result = $this->privList($p_list)) != 1) { unset($p_list); return(0); } // ----- Return return $p_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : // extract($p_path="./", $p_remove_path="") // extract([$p_option, $p_option_value, ...]) // Description : // This method supports two synopsis. The first one is historical. // This method extract all the files / directories from the archive to the // folder indicated in $p_path. // If you want to ignore the 'root' part of path of the memorized files // you can indicate this in the optional $p_remove_path parameter. // By default, if a newer file with the same name already exists, the // file is not extracted. // // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append // at the end of the path value of PCLZIP_OPT_PATH. // Parameters : // $p_path : Path where the files and directories are to be extracted // $p_remove_path : First part ('root' part) of the memorized path // (if any similar) to remove while extracting. // Options : // PCLZIP_OPT_PATH : // PCLZIP_OPT_ADD_PATH : // PCLZIP_OPT_REMOVE_PATH : // PCLZIP_OPT_REMOVE_ALL_PATH : // PCLZIP_CB_PRE_EXTRACT : // PCLZIP_CB_POST_EXTRACT : // Return Values : // 0 or a negative value on failure, // The list of the extracted files, with a status of the action. // (see PclZip::listContent() for list entry format) // -------------------------------------------------------------------------------- function extract() { $v_result=1; // ----- Reset the error handler $this->privErrorReset(); // ----- Check archive if (!$this->privCheckFormat()) { return(0); } // ----- Set default values $v_options = array(); // $v_path = "./"; $v_path = ''; $v_remove_path = ""; $v_remove_all_path = false; // ----- Look for variable options arguments $v_size = func_num_args(); // ----- Default values for option $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; // ----- Look for arguments if ($v_size > 0) { // ----- Get the arguments $v_arg_list = func_get_args(); // ----- Look for first arg if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_PATH => 'optional', PCLZIP_OPT_REMOVE_PATH => 'optional', PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', PCLZIP_OPT_ADD_PATH => 'optional', PCLZIP_CB_PRE_EXTRACT => 'optional', PCLZIP_CB_POST_EXTRACT => 'optional', PCLZIP_OPT_SET_CHMOD => 'optional', PCLZIP_OPT_BY_NAME => 'optional', PCLZIP_OPT_BY_EREG => 'optional', PCLZIP_OPT_BY_PREG => 'optional', PCLZIP_OPT_BY_INDEX => 'optional', PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', PCLZIP_OPT_REPLACE_NEWER => 'optional' ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', PCLZIP_OPT_TEMP_FILE_ON => 'optional', PCLZIP_OPT_TEMP_FILE_OFF => 'optional' )); if ($v_result != 1) { return 0; } // ----- Set the arguments if (isset($v_options[PCLZIP_OPT_PATH])) { $v_path = $v_options[PCLZIP_OPT_PATH]; } if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; } if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; } if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { // ----- Check for '/' in last path char if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { $v_path .= '/'; } $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; } } // ----- Look for 2 args // Here we need to support the first historic synopsis of the // method. else { // ----- Get the first argument $v_path = $v_arg_list[0]; // ----- Look for the optional second argument if ($v_size == 2) { $v_remove_path = $v_arg_list[1]; } else if ($v_size > 2) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); // ----- Return return 0; } } } // ----- Look for default option values $this->privOptionDefaultThreshold($v_options); // ----- Trace // ----- Call the extracting fct $p_list = array(); $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options); if ($v_result < 1) { unset($p_list); return(0); } // ----- Return return $p_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : // extractByIndex($p_index, $p_path="./", $p_remove_path="") // extractByIndex($p_index, [$p_option, $p_option_value, ...]) // Description : // This method supports two synopsis. The first one is historical. // This method is doing a partial extract of the archive. // The extracted files or folders are identified by their index in the // archive (from 0 to n). // Note that if the index identify a folder, only the folder entry is // extracted, not all the files included in the archive. // Parameters : // $p_index : A single index (integer) or a string of indexes of files to // extract. The form of the string is "0,4-6,8-12" with only numbers // and '-' for range or ',' to separate ranges. No spaces or ';' // are allowed. // $p_path : Path where the files and directories are to be extracted // $p_remove_path : First part ('root' part) of the memorized path // (if any similar) to remove while extracting. // Options : // PCLZIP_OPT_PATH : // PCLZIP_OPT_ADD_PATH : // PCLZIP_OPT_REMOVE_PATH : // PCLZIP_OPT_REMOVE_ALL_PATH : // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and // not as files. // The resulting content is in a new field 'content' in the file // structure. // This option must be used alone (any other options are ignored). // PCLZIP_CB_PRE_EXTRACT : // PCLZIP_CB_POST_EXTRACT : // Return Values : // 0 on failure, // The list of the extracted files, with a status of the action. // (see PclZip::listContent() for list entry format) // -------------------------------------------------------------------------------- //function extractByIndex($p_index, options...) function extractByIndex($p_index) { $v_result=1; // ----- Reset the error handler $this->privErrorReset(); // ----- Check archive if (!$this->privCheckFormat()) { return(0); } // ----- Set default values $v_options = array(); // $v_path = "./"; $v_path = ''; $v_remove_path = ""; $v_remove_all_path = false; // ----- Look for variable options arguments $v_size = func_num_args(); // ----- Default values for option $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; // ----- Look for arguments if ($v_size > 1) { // ----- Get the arguments $v_arg_list = func_get_args(); // ----- Remove form the options list the first argument array_shift($v_arg_list); $v_size--; // ----- Look for first arg if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_PATH => 'optional', PCLZIP_OPT_REMOVE_PATH => 'optional', PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', PCLZIP_OPT_ADD_PATH => 'optional', PCLZIP_CB_PRE_EXTRACT => 'optional', PCLZIP_CB_POST_EXTRACT => 'optional', PCLZIP_OPT_SET_CHMOD => 'optional', PCLZIP_OPT_REPLACE_NEWER => 'optional' ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', PCLZIP_OPT_TEMP_FILE_ON => 'optional', PCLZIP_OPT_TEMP_FILE_OFF => 'optional' )); if ($v_result != 1) { return 0; } // ----- Set the arguments if (isset($v_options[PCLZIP_OPT_PATH])) { $v_path = $v_options[PCLZIP_OPT_PATH]; } if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; } if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; } if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { // ----- Check for '/' in last path char if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { $v_path .= '/'; } $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; } if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; } else { } } // ----- Look for 2 args // Here we need to support the first historic synopsis of the // method. else { // ----- Get the first argument $v_path = $v_arg_list[0]; // ----- Look for the optional second argument if ($v_size == 2) { $v_remove_path = $v_arg_list[1]; } else if ($v_size > 2) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); // ----- Return return 0; } } } // ----- Trace // ----- Trick // Here I want to reuse extractByRule(), so I need to parse the $p_index // with privParseOptions() $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); $v_options_trick = array(); $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, array (PCLZIP_OPT_BY_INDEX => 'optional' )); if ($v_result != 1) { return 0; } $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; // ----- Look for default option values $this->privOptionDefaultThreshold($v_options); // ----- Call the extracting fct if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { return(0); } // ----- Return return $p_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : // delete([$p_option, $p_option_value, ...]) // Description : // This method removes files from the archive. // If no parameters are given, then all the archive is emptied. // Parameters : // None or optional arguments. // Options : // PCLZIP_OPT_BY_INDEX : // PCLZIP_OPT_BY_NAME : // PCLZIP_OPT_BY_EREG : // PCLZIP_OPT_BY_PREG : // Return Values : // 0 on failure, // The list of the files which are still present in the archive. // (see PclZip::listContent() for list entry format) // -------------------------------------------------------------------------------- function delete() { $v_result=1; // ----- Reset the error handler $this->privErrorReset(); // ----- Check archive if (!$this->privCheckFormat()) { return(0); } // ----- Set default values $v_options = array(); // ----- Look for variable options arguments $v_size = func_num_args(); // ----- Look for arguments if ($v_size > 0) { // ----- Get the arguments $v_arg_list = func_get_args(); // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_BY_NAME => 'optional', PCLZIP_OPT_BY_EREG => 'optional', PCLZIP_OPT_BY_PREG => 'optional', PCLZIP_OPT_BY_INDEX => 'optional' )); if ($v_result != 1) { return 0; } } // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Call the delete fct $v_list = array(); if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { $this->privSwapBackMagicQuotes(); unset($v_list); return(0); } // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Return return $v_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : deleteByIndex() // Description : // ***** Deprecated ***** // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered. // -------------------------------------------------------------------------------- function deleteByIndex($p_index) { $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); // ----- Return return $p_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : properties() // Description : // This method gives the properties of the archive. // The properties are : // nb : Number of files in the archive // comment : Comment associated with the archive file // status : not_exist, ok // Parameters : // None // Return Values : // 0 on failure, // An array with the archive properties. // -------------------------------------------------------------------------------- function properties() { // ----- Reset the error handler $this->privErrorReset(); // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Check archive if (!$this->privCheckFormat()) { $this->privSwapBackMagicQuotes(); return(0); } // ----- Default properties $v_prop = array(); $v_prop['comment'] = ''; $v_prop['nb'] = 0; $v_prop['status'] = 'not_exist'; // ----- Look if file exists if (@is_file($this->zipname)) { // ----- Open the zip file if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) { $this->privSwapBackMagicQuotes(); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); // ----- Return return 0; } // ----- Read the central directory informations $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privSwapBackMagicQuotes(); return 0; } // ----- Close the zip file $this->privCloseFd(); // ----- Set the user attributes $v_prop['comment'] = $v_central_dir['comment']; $v_prop['nb'] = $v_central_dir['entries']; $v_prop['status'] = 'ok'; } // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Return return $v_prop; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : duplicate() // Description : // This method creates an archive by copying the content of an other one. If // the archive already exist, it is replaced by the new one without any warning. // Parameters : // $p_archive : The filename of a valid archive, or // a valid PclZip object. // Return Values : // 1 on success. // 0 or a negative value on error (error code). // -------------------------------------------------------------------------------- function duplicate($p_archive) { $v_result = 1; // ----- Reset the error handler $this->privErrorReset(); // ----- Look if the $p_archive is a PclZip object if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) { // ----- Duplicate the archive $v_result = $this->privDuplicate($p_archive->zipname); } // ----- Look if the $p_archive is a string (so a filename) else if (is_string($p_archive)) { // ----- Check that $p_archive is a valid zip file // TBC : Should also check the archive format if (!is_file($p_archive)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); $v_result = PCLZIP_ERR_MISSING_FILE; } else { // ----- Duplicate the archive $v_result = $this->privDuplicate($p_archive); } } // ----- Invalid variable else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); $v_result = PCLZIP_ERR_INVALID_PARAMETER; } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : merge() // Description : // This method merge the $p_archive_to_add archive at the end of the current // one ($this). // If the archive ($this) does not exist, the merge becomes a duplicate. // If the $p_archive_to_add archive does not exist, the merge is a success. // Parameters : // $p_archive_to_add : It can be directly the filename of a valid zip archive, // or a PclZip object archive. // Return Values : // 1 on success, // 0 or negative values on error (see below). // -------------------------------------------------------------------------------- function merge($p_archive_to_add) { $v_result = 1; // ----- Reset the error handler $this->privErrorReset(); // ----- Check archive if (!$this->privCheckFormat()) { return(0); } // ----- Look if the $p_archive_to_add is a PclZip object if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) { // ----- Merge the archive $v_result = $this->privMerge($p_archive_to_add); } // ----- Look if the $p_archive_to_add is a string (so a filename) else if (is_string($p_archive_to_add)) { // ----- Create a temporary archive $v_object_archive = new PclZip($p_archive_to_add); // ----- Merge the archive $v_result = $this->privMerge($v_object_archive); } // ----- Invalid variable else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); $v_result = PCLZIP_ERR_INVALID_PARAMETER; } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : errorCode() // Description : // Parameters : // -------------------------------------------------------------------------------- function errorCode() { if (PCLZIP_ERROR_EXTERNAL == 1) { return(PclErrorCode()); } else { return($this->error_code); } } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : errorName() // Description : // Parameters : // -------------------------------------------------------------------------------- function errorName($p_with_code=false) { $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' ); if (isset($v_name[$this->error_code])) { $v_value = $v_name[$this->error_code]; } else { $v_value = 'NoName'; } if ($p_with_code) { return($v_value.' ('.$this->error_code.')'); } else { return($v_value); } } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : errorInfo() // Description : // Parameters : // -------------------------------------------------------------------------------- function errorInfo($p_full=false) { if (PCLZIP_ERROR_EXTERNAL == 1) { return(PclErrorString()); } else { if ($p_full) { return($this->errorName(true)." : ".$this->error_string); } else { return($this->error_string." [code ".$this->error_code."]"); } } } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS ***** // ***** ***** // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY ***** // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privCheckFormat() // Description : // This method check that the archive exists and is a valid zip archive. // Several level of check exists. (futur) // Parameters : // $p_level : Level of check. Default 0. // 0 : Check the first bytes (magic codes) (default value)) // 1 : 0 + Check the central directory (futur) // 2 : 1 + Check each file header (futur) // Return Values : // true on success, // false on error, the error code is set. // -------------------------------------------------------------------------------- function privCheckFormat($p_level=0) { $v_result = true; // ----- Reset the file system cache clearstatcache(); // ----- Reset the error handler $this->privErrorReset(); // ----- Look if the file exits if (!is_file($this->zipname)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); return(false); } // ----- Check that the file is readeable if (!is_readable($this->zipname)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); return(false); } // ----- Check the magic code // TBC // ----- Check the central header // TBC // ----- Check each file header // TBC // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privParseOptions() // Description : // This internal methods reads the variable list of arguments ($p_options_list, // $p_size) and generate an array with the options and values ($v_result_list). // $v_requested_options contains the options that can be present and those that // must be present. // $v_requested_options is an array, with the option value as key, and 'optional', // or 'mandatory' as value. // Parameters : // See above. // Return Values : // 1 on success. // 0 on failure. // -------------------------------------------------------------------------------- function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) { $v_result=1; // ----- Read the options $i=0; while ($i<$p_size) { // ----- Check if the option is supported if (!isset($v_requested_options[$p_options_list[$i]])) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); // ----- Return return PclZip::errorCode(); } // ----- Look for next option switch ($p_options_list[$i]) { // ----- Look for options that request a path value case PCLZIP_OPT_PATH : case PCLZIP_OPT_REMOVE_PATH : case PCLZIP_OPT_ADD_PATH : // ----- Check the number of parameters if (($i+1) >= $p_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Get the value $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); $i++; break; case PCLZIP_OPT_TEMP_FILE_THRESHOLD : // ----- Check the number of parameters if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } // ----- Check for incompatible options if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); return PclZip::errorCode(); } // ----- Check the value $v_value = $p_options_list[$i+1]; if ((!is_integer($v_value)) || ($v_value<0)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } // ----- Get the value (and convert it in bytes) $v_result_list[$p_options_list[$i]] = $v_value*1048576; $i++; break; case PCLZIP_OPT_TEMP_FILE_ON : // ----- Check for incompatible options if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); return PclZip::errorCode(); } $v_result_list[$p_options_list[$i]] = true; break; case PCLZIP_OPT_TEMP_FILE_OFF : // ----- Check for incompatible options if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); return PclZip::errorCode(); } // ----- Check for incompatible options if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); return PclZip::errorCode(); } $v_result_list[$p_options_list[$i]] = true; break; case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : // ----- Check the number of parameters if (($i+1) >= $p_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Get the value if ( is_string($p_options_list[$i+1]) && ($p_options_list[$i+1] != '')) { $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); $i++; } else { } break; // ----- Look for options that request an array of string for value case PCLZIP_OPT_BY_NAME : // ----- Check the number of parameters if (($i+1) >= $p_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Get the value if (is_string($p_options_list[$i+1])) { $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; } else if (is_array($p_options_list[$i+1])) { $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; } else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } $i++; break; // ----- Look for options that request an EREG or PREG expression case PCLZIP_OPT_BY_EREG : // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG // to PCLZIP_OPT_BY_PREG $p_options_list[$i] = PCLZIP_OPT_BY_PREG; case PCLZIP_OPT_BY_PREG : //case PCLZIP_OPT_CRYPT : // ----- Check the number of parameters if (($i+1) >= $p_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Get the value if (is_string($p_options_list[$i+1])) { $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; } else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } $i++; break; // ----- Look for options that takes a string case PCLZIP_OPT_COMMENT : case PCLZIP_OPT_ADD_COMMENT : case PCLZIP_OPT_PREPEND_COMMENT : // ----- Check the number of parameters if (($i+1) >= $p_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" .PclZipUtilOptionText($p_options_list[$i]) ."'"); // ----- Return return PclZip::errorCode(); } // ----- Get the value if (is_string($p_options_list[$i+1])) { $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; } else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '" .PclZipUtilOptionText($p_options_list[$i]) ."'"); // ----- Return return PclZip::errorCode(); } $i++; break; // ----- Look for options that request an array of index case PCLZIP_OPT_BY_INDEX : // ----- Check the number of parameters if (($i+1) >= $p_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Get the value $v_work_list = array(); if (is_string($p_options_list[$i+1])) { // ----- Remove spaces $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); // ----- Parse items $v_work_list = explode(",", $p_options_list[$i+1]); } else if (is_integer($p_options_list[$i+1])) { $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; } else if (is_array($p_options_list[$i+1])) { $v_work_list = $p_options_list[$i+1]; } else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Reduce the index list // each index item in the list must be a couple with a start and // an end value : [0,3], [5-5], [8-10], ... // ----- Check the format of each item $v_sort_flag=false; $v_sort_value=0; for ($j=0; $j<sizeof($v_work_list); $j++) { // ----- Explode the item $v_item_list = explode("-", $v_work_list[$j]); $v_size_item_list = sizeof($v_item_list); // ----- TBC : Here we might check that each item is a // real integer ... // ----- Look for single value if ($v_size_item_list == 1) { // ----- Set the option value $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; } elseif ($v_size_item_list == 2) { // ----- Set the option value $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; } else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Look for list sort if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { $v_sort_flag=true; // ----- TBC : An automatic sort should be writen ... // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; } // ----- Sort the items if ($v_sort_flag) { // TBC : To Be Completed } // ----- Next option $i++; break; // ----- Look for options that request no value case PCLZIP_OPT_REMOVE_ALL_PATH : case PCLZIP_OPT_EXTRACT_AS_STRING : case PCLZIP_OPT_NO_COMPRESSION : case PCLZIP_OPT_EXTRACT_IN_OUTPUT : case PCLZIP_OPT_REPLACE_NEWER : case PCLZIP_OPT_STOP_ON_ERROR : $v_result_list[$p_options_list[$i]] = true; break; // ----- Look for options that request an octal value case PCLZIP_OPT_SET_CHMOD : // ----- Check the number of parameters if (($i+1) >= $p_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Get the value $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; $i++; break; // ----- Look for options that request a call-back case PCLZIP_CB_PRE_EXTRACT : case PCLZIP_CB_POST_EXTRACT : case PCLZIP_CB_PRE_ADD : case PCLZIP_CB_POST_ADD : /* for futur use case PCLZIP_CB_PRE_DELETE : case PCLZIP_CB_POST_DELETE : case PCLZIP_CB_PRE_LIST : case PCLZIP_CB_POST_LIST : */ // ----- Check the number of parameters if (($i+1) >= $p_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Get the value $v_function_name = $p_options_list[$i+1]; // ----- Check that the value is a valid existing function if (!function_exists($v_function_name)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Set the attribute $v_result_list[$p_options_list[$i]] = $v_function_name; $i++; break; default : // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Unknown parameter '" .$p_options_list[$i]."'"); // ----- Return return PclZip::errorCode(); } // ----- Next options $i++; } // ----- Look for mandatory options if ($v_requested_options !== false) { for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { // ----- Look for mandatory option if ($v_requested_options[$key] == 'mandatory') { // ----- Look if present if (!isset($v_result_list[$key])) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); // ----- Return return PclZip::errorCode(); } } } } // ----- Look for default values if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privOptionDefaultThreshold() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privOptionDefaultThreshold(&$p_options) { $v_result=1; if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { return $v_result; } // ----- Get 'memory_limit' configuration value $v_memory_limit = ini_get('memory_limit'); $v_memory_limit = trim($v_memory_limit); $last = strtolower(substr($v_memory_limit, -1)); if($last == 'g') //$v_memory_limit = $v_memory_limit*1024*1024*1024; $v_memory_limit = $v_memory_limit*1073741824; if($last == 'm') //$v_memory_limit = $v_memory_limit*1024*1024; $v_memory_limit = $v_memory_limit*1048576; if($last == 'k') $v_memory_limit = $v_memory_limit*1024; $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); // ----- Sanity check : No threshold if value lower than 1M if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) { unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privFileDescrParseAtt() // Description : // Parameters : // Return Values : // 1 on success. // 0 on failure. // -------------------------------------------------------------------------------- function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) { $v_result=1; // ----- For each file in the list check the attributes foreach ($p_file_list as $v_key => $v_value) { // ----- Check if the option is supported if (!isset($v_requested_options[$v_key])) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); // ----- Return return PclZip::errorCode(); } // ----- Look for attribute switch ($v_key) { case PCLZIP_ATT_FILE_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); if ($p_filedescr['filename'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } break; case PCLZIP_ATT_FILE_NEW_SHORT_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); if ($p_filedescr['new_short_name'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } break; case PCLZIP_ATT_FILE_NEW_FULL_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); if ($p_filedescr['new_full_name'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } break; // ----- Look for options that takes a string case PCLZIP_ATT_FILE_COMMENT : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['comment'] = $v_value; break; case PCLZIP_ATT_FILE_MTIME : if (!is_integer($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['mtime'] = $v_value; break; case PCLZIP_ATT_FILE_CONTENT : $p_filedescr['content'] = $v_value; break; default : // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Unknown parameter '".$v_key."'"); // ----- Return return PclZip::errorCode(); } // ----- Look for mandatory options if ($v_requested_options !== false) { for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { // ----- Look for mandatory option if ($v_requested_options[$key] == 'mandatory') { // ----- Look if present if (!isset($p_file_list[$key])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); return PclZip::errorCode(); } } } } // end foreach } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privFileDescrExpand() // Description : // This method look for each item of the list to see if its a file, a folder // or a string to be added as file. For any other type of files (link, other) // just ignore the item. // Then prepare the information that will be stored for that file. // When its a folder, expand the folder with all the files that are in that // folder (recursively). // Parameters : // Return Values : // 1 on success. // 0 on failure. // -------------------------------------------------------------------------------- function privFileDescrExpand(&$p_filedescr_list, &$p_options) { $v_result=1; // ----- Create a result list $v_result_list = array(); // ----- Look each entry for ($i=0; $i<sizeof($p_filedescr_list); $i++) { // ----- Get filedescr $v_descr = $p_filedescr_list[$i]; // ----- Reduce the filename $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); // ----- Look for real file or folder if (file_exists($v_descr['filename'])) { if (@is_file($v_descr['filename'])) { $v_descr['type'] = 'file'; } else if (@is_dir($v_descr['filename'])) { $v_descr['type'] = 'folder'; } else if (@is_link($v_descr['filename'])) { // skip continue; } else { // skip continue; } } // ----- Look for string added as file else if (isset($v_descr['content'])) { $v_descr['type'] = 'virtual_file'; } // ----- Missing file else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); // ----- Return return PclZip::errorCode(); } // ----- Calculate the stored filename $this->privCalculateStoredFilename($v_descr, $p_options); // ----- Add the descriptor in result list $v_result_list[sizeof($v_result_list)] = $v_descr; // ----- Look for folder if ($v_descr['type'] == 'folder') { // ----- List of items in folder $v_dirlist_descr = array(); $v_dirlist_nb = 0; if ($v_folder_handler = @opendir($v_descr['filename'])) { while (($v_item_handler = @readdir($v_folder_handler)) !== false) { // ----- Skip '.' and '..' if (($v_item_handler == '.') || ($v_item_handler == '..')) { continue; } // ----- Compose the full filename $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; // ----- Look for different stored filename // Because the name of the folder was changed, the name of the // files/sub-folders also change if (($v_descr['stored_filename'] != $v_descr['filename']) && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { if ($v_descr['stored_filename'] != '') { $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; } else { $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; } } $v_dirlist_nb++; } @closedir($v_folder_handler); } else { // TBC : unable to open folder in read mode } // ----- Expand each element of the list if ($v_dirlist_nb != 0) { // ----- Expand if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { return $v_result; } // ----- Concat the resulting list $v_result_list = array_merge($v_result_list, $v_dirlist_descr); } else { } // ----- Free local array unset($v_dirlist_descr); } } // ----- Get the result list $p_filedescr_list = $v_result_list; // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privCreate() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privCreate($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; $v_list_detail = array(); // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Open the file in write mode if (($v_result = $this->privOpenFd('wb')) != 1) { // ----- Return return $v_result; } // ----- Add the list of files $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); // ----- Close $this->privCloseFd(); // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privAdd() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privAdd($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; $v_list_detail = array(); // ----- Look if the archive exists or is empty if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) { // ----- Do a create $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); // ----- Return return $v_result; } // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Open the zip file if (($v_result=$this->privOpenFd('rb')) != 1) { // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Return return $v_result; } // ----- Read the central directory informations $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Go to beginning of File @rewind($this->zip_fd); // ----- Creates a temporay file $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; // ----- Open the temporary file in write mode if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); // ----- Return return PclZip::errorCode(); } // ----- Copy the files from the archive to the temporary file // TBC : Here I should better append the file and go back to erase the central dir $v_size = $v_central_dir['offset']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Swap the file descriptor // Here is a trick : I swap the temporary fd with the zip fd, in order to use // the following methods on the temporary fil and not the real archive $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; // ----- Add the files $v_header_list = array(); if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) { fclose($v_zip_temp_fd); $this->privCloseFd(); @unlink($v_zip_temp_name); $this->privSwapBackMagicQuotes(); // ----- Return return $v_result; } // ----- Store the offset of the central dir $v_offset = @ftell($this->zip_fd); // ----- Copy the block of file headers from the old archive $v_size = $v_central_dir['size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($v_zip_temp_fd, $v_read_size); @fwrite($this->zip_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Create the Central Dir files header for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) { // ----- Create the file header if ($v_header_list[$i]['status'] == 'ok') { if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { fclose($v_zip_temp_fd); $this->privCloseFd(); @unlink($v_zip_temp_name); $this->privSwapBackMagicQuotes(); // ----- Return return $v_result; } $v_count++; } // ----- Transform the header to a 'usable' info $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); } // ----- Zip file comment $v_comment = $v_central_dir['comment']; if (isset($p_options[PCLZIP_OPT_COMMENT])) { $v_comment = $p_options[PCLZIP_OPT_COMMENT]; } if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; } if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; } // ----- Calculate the size of the central header $v_size = @ftell($this->zip_fd)-$v_offset; // ----- Create the central dir footer if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) { // ----- Reset the file list unset($v_header_list); $this->privSwapBackMagicQuotes(); // ----- Return return $v_result; } // ----- Swap back the file descriptor $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; // ----- Close $this->privCloseFd(); // ----- Close the temporary file @fclose($v_zip_temp_fd); // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Delete the zip file // TBC : I should test the result ... @unlink($this->zipname); // ----- Rename the temporary file // TBC : I should test the result ... //@rename($v_zip_temp_name, $this->zipname); PclZipUtilRename($v_zip_temp_name, $this->zipname); // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privOpenFd() // Description : // Parameters : // -------------------------------------------------------------------------------- function privOpenFd($p_mode) { $v_result=1; // ----- Look if already open if ($this->zip_fd != 0) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); // ----- Return return PclZip::errorCode(); } // ----- Open the zip file if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); // ----- Return return PclZip::errorCode(); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privCloseFd() // Description : // Parameters : // -------------------------------------------------------------------------------- function privCloseFd() { $v_result=1; if ($this->zip_fd != 0) @fclose($this->zip_fd); $this->zip_fd = 0; // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privAddList() // Description : // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is // different from the real path of the file. This is usefull if you want to have PclTar // running in any directory, and memorize relative path from an other directory. // Parameters : // $p_list : An array containing the file or directory names to add in the tar // $p_result_list : list of added files with their properties (specially the status field) // $p_add_dir : Path to add in the filename path archived // $p_remove_dir : Path to remove in the filename path archived // Return Values : // -------------------------------------------------------------------------------- // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options) function privAddList($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; // ----- Add the files $v_header_list = array(); if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) { // ----- Return return $v_result; } // ----- Store the offset of the central dir $v_offset = @ftell($this->zip_fd); // ----- Create the Central Dir files header for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) { // ----- Create the file header if ($v_header_list[$i]['status'] == 'ok') { if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { // ----- Return return $v_result; } $v_count++; } // ----- Transform the header to a 'usable' info $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); } // ----- Zip file comment $v_comment = ''; if (isset($p_options[PCLZIP_OPT_COMMENT])) { $v_comment = $p_options[PCLZIP_OPT_COMMENT]; } // ----- Calculate the size of the central header $v_size = @ftell($this->zip_fd)-$v_offset; // ----- Create the central dir footer if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) { // ----- Reset the file list unset($v_header_list); // ----- Return return $v_result; } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privAddFileList() // Description : // Parameters : // $p_filedescr_list : An array containing the file description // or directory names to add in the zip // $p_result_list : list of added files with their properties (specially the status field) // Return Values : // -------------------------------------------------------------------------------- function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; $v_header = array(); // ----- Recuperate the current number of elt in list $v_nb = sizeof($p_result_list); // ----- Loop on the files for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { // ----- Format the filename $p_filedescr_list[$j]['filename'] = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); // ----- Skip empty file names // TBC : Can this be possible ? not checked in DescrParseAtt ? if ($p_filedescr_list[$j]['filename'] == "") { continue; } // ----- Check the filename if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') && (!file_exists($p_filedescr_list[$j]['filename']))) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); return PclZip::errorCode(); } // ----- Look if it is a file or a dir with no all path remove option // or a dir with all its path removed // if ( (is_file($p_filedescr_list[$j]['filename'])) // || ( is_dir($p_filedescr_list[$j]['filename']) if ( ($p_filedescr_list[$j]['type'] == 'file') || ($p_filedescr_list[$j]['type'] == 'virtual_file') || ( ($p_filedescr_list[$j]['type'] == 'folder') && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) ) { // ----- Add the file $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, $p_options); if ($v_result != 1) { return $v_result; } // ----- Store the file infos $p_result_list[$v_nb++] = $v_header; } } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privAddFile() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privAddFile($p_filedescr, &$p_header, &$p_options) { $v_result=1; // ----- Working variable $p_filename = $p_filedescr['filename']; // TBC : Already done in the fileAtt check ... ? if ($p_filename == "") { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); // ----- Return return PclZip::errorCode(); } // ----- Look for a stored different filename /* TBC : Removed if (isset($p_filedescr['stored_filename'])) { $v_stored_filename = $p_filedescr['stored_filename']; } else { $v_stored_filename = $p_filedescr['stored_filename']; } */ // ----- Set the file properties clearstatcache(); $p_header['version'] = 20; $p_header['version_extracted'] = 10; $p_header['flag'] = 0; $p_header['compression'] = 0; $p_header['crc'] = 0; $p_header['compressed_size'] = 0; $p_header['filename_len'] = strlen($p_filename); $p_header['extra_len'] = 0; $p_header['disk'] = 0; $p_header['internal'] = 0; $p_header['offset'] = 0; $p_header['filename'] = $p_filename; // TBC : Removed $p_header['stored_filename'] = $v_stored_filename; $p_header['stored_filename'] = $p_filedescr['stored_filename']; $p_header['extra'] = ''; $p_header['status'] = 'ok'; $p_header['index'] = -1; // ----- Look for regular file if ($p_filedescr['type']=='file') { $p_header['external'] = 0x00000000; $p_header['size'] = filesize($p_filename); } // ----- Look for regular folder else if ($p_filedescr['type']=='folder') { $p_header['external'] = 0x00000010; $p_header['mtime'] = filemtime($p_filename); $p_header['size'] = filesize($p_filename); } // ----- Look for virtual file else if ($p_filedescr['type'] == 'virtual_file') { $p_header['external'] = 0x00000000; $p_header['size'] = strlen($p_filedescr['content']); } // ----- Look for filetime if (isset($p_filedescr['mtime'])) { $p_header['mtime'] = $p_filedescr['mtime']; } else if ($p_filedescr['type'] == 'virtual_file') { $p_header['mtime'] = time(); } else { $p_header['mtime'] = filemtime($p_filename); } // ------ Look for file comment if (isset($p_filedescr['comment'])) { $p_header['comment_len'] = strlen($p_filedescr['comment']); $p_header['comment'] = $p_filedescr['comment']; } else { $p_header['comment_len'] = 0; $p_header['comment'] = ''; } // ----- Look for pre-add callback if (isset($p_options[PCLZIP_CB_PRE_ADD])) { // ----- Generate a local information $v_local_header = array(); $this->privConvertHeader2FileInfo($p_header, $v_local_header); // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header); if ($v_result == 0) { // ----- Change the file status $p_header['status'] = "skipped"; $v_result = 1; } // ----- Update the informations // Only some fields can be modified if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); } } // ----- Look for empty stored filename if ($p_header['stored_filename'] == "") { $p_header['status'] = "filtered"; } // ----- Check the path length if (strlen($p_header['stored_filename']) > 0xFF) { $p_header['status'] = 'filename_too_long'; } // ----- Look if no error, or file not skipped if ($p_header['status'] == 'ok') { // ----- Look for a file if ($p_filedescr['type'] == 'file') { // ----- Look for using temporary file to zip if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); if ($v_result < PCLZIP_ERR_NO_ERROR) { return $v_result; } } // ----- Use "in memory" zip algo else { // ----- Open the source file if (($v_file = @fopen($p_filename, "rb")) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); return PclZip::errorCode(); } // ----- Read the file content $v_content = @fread($v_file, $p_header['size']); // ----- Close the file @fclose($v_file); // ----- Calculate the CRC $p_header['crc'] = @crc32($v_content); // ----- Look for no compression if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { // ----- Set header parameters $p_header['compressed_size'] = $p_header['size']; $p_header['compression'] = 0; } // ----- Look for normal compression else { // ----- Compress the content $v_content = @gzdeflate($v_content); // ----- Set header parameters $p_header['compressed_size'] = strlen($v_content); $p_header['compression'] = 8; } // ----- Call the header generation if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { @fclose($v_file); return $v_result; } // ----- Write the compressed (or not) content @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); } } // ----- Look for a virtual file (a file from string) else if ($p_filedescr['type'] == 'virtual_file') { $v_content = $p_filedescr['content']; // ----- Calculate the CRC $p_header['crc'] = @crc32($v_content); // ----- Look for no compression if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { // ----- Set header parameters $p_header['compressed_size'] = $p_header['size']; $p_header['compression'] = 0; } // ----- Look for normal compression else { // ----- Compress the content $v_content = @gzdeflate($v_content); // ----- Set header parameters $p_header['compressed_size'] = strlen($v_content); $p_header['compression'] = 8; } // ----- Call the header generation if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { @fclose($v_file); return $v_result; } // ----- Write the compressed (or not) content @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); } // ----- Look for a directory else if ($p_filedescr['type'] == 'folder') { // ----- Look for directory last '/' if (@substr($p_header['stored_filename'], -1) != '/') { $p_header['stored_filename'] .= '/'; } // ----- Set the file properties $p_header['size'] = 0; //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked $p_header['external'] = 0x00000010; // Value for a folder : to be checked // ----- Call the header generation if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { return $v_result; } } } // ----- Look for post-add callback if (isset($p_options[PCLZIP_CB_POST_ADD])) { // ----- Generate a local information $v_local_header = array(); $this->privConvertHeader2FileInfo($p_header, $v_local_header); // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header); if ($v_result == 0) { // ----- Ignored $v_result = 1; } // ----- Update the informations // Nothing can be modified } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privAddFileUsingTempFile() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) { $v_result=PCLZIP_ERR_NO_ERROR; // ----- Working variable $p_filename = $p_filedescr['filename']; // ----- Open the source file if (($v_file = @fopen($p_filename, "rb")) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); return PclZip::errorCode(); } // ----- Creates a compressed temporary file $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { fclose($v_file); PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); return PclZip::errorCode(); } // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks $v_size = filesize($p_filename); while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($v_file, $v_read_size); //$v_binary_data = pack('a'.$v_read_size, $v_buffer); @gzputs($v_file_compressed, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Close the file @fclose($v_file); @gzclose($v_file_compressed); // ----- Check the minimum file size if (filesize($v_gzip_temp_name) < 18) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); return PclZip::errorCode(); } // ----- Extract the compressed attributes if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); return PclZip::errorCode(); } // ----- Read the gzip file header $v_binary_data = @fread($v_file_compressed, 10); $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); // ----- Check some parameters $v_data_header['os'] = bin2hex($v_data_header['os']); // ----- Read the gzip file footer @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); $v_binary_data = @fread($v_file_compressed, 8); $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); // ----- Set the attributes $p_header['compression'] = ord($v_data_header['cm']); //$p_header['mtime'] = $v_data_header['mtime']; $p_header['crc'] = $v_data_footer['crc']; $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; // ----- Close the file @fclose($v_file_compressed); // ----- Call the header generation if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { return $v_result; } // ----- Add the compressed data if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); return PclZip::errorCode(); } // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks fseek($v_file_compressed, 10); $v_size = $p_header['compressed_size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($v_file_compressed, $v_read_size); //$v_binary_data = pack('a'.$v_read_size, $v_buffer); @fwrite($this->zip_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Close the file @fclose($v_file_compressed); // ----- Unlink the temporary file @unlink($v_gzip_temp_name); // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privCalculateStoredFilename() // Description : // Based on file descriptor properties and global options, this method // calculate the filename that will be stored in the archive. // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privCalculateStoredFilename(&$p_filedescr, &$p_options) { $v_result=1; // ----- Working variables $p_filename = $p_filedescr['filename']; if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; } else { $p_add_dir = ''; } if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; } else { $p_remove_dir = ''; } if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; } else { $p_remove_all_dir = 0; } // ----- Look for full name change if (isset($p_filedescr['new_full_name'])) { // ----- Remove drive letter if any $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); } // ----- Look for path and/or short name change else { // ----- Look for short name change // Its when we cahnge just the filename but not the path if (isset($p_filedescr['new_short_name'])) { $v_path_info = pathinfo($p_filename); $v_dir = ''; if ($v_path_info['dirname'] != '') { $v_dir = $v_path_info['dirname'].'/'; } $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; } else { // ----- Calculate the stored filename $v_stored_filename = $p_filename; } // ----- Look for all path to remove if ($p_remove_all_dir) { $v_stored_filename = basename($p_filename); } // ----- Look for partial path remove else if ($p_remove_dir != "") { if (substr($p_remove_dir, -1) != '/') $p_remove_dir .= "/"; if ( (substr($p_filename, 0, 2) == "./") || (substr($p_remove_dir, 0, 2) == "./")) { if ( (substr($p_filename, 0, 2) == "./") && (substr($p_remove_dir, 0, 2) != "./")) { $p_remove_dir = "./".$p_remove_dir; } if ( (substr($p_filename, 0, 2) != "./") && (substr($p_remove_dir, 0, 2) == "./")) { $p_remove_dir = substr($p_remove_dir, 2); } } $v_compare = PclZipUtilPathInclusion($p_remove_dir, $v_stored_filename); if ($v_compare > 0) { if ($v_compare == 2) { $v_stored_filename = ""; } else { $v_stored_filename = substr($v_stored_filename, strlen($p_remove_dir)); } } } // ----- Remove drive letter if any $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); // ----- Look for path to add if ($p_add_dir != "") { if (substr($p_add_dir, -1) == "/") $v_stored_filename = $p_add_dir.$v_stored_filename; else $v_stored_filename = $p_add_dir."/".$v_stored_filename; } } // ----- Filename (reduce the path of stored name) $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); $p_filedescr['stored_filename'] = $v_stored_filename; // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privWriteFileHeader() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privWriteFileHeader(&$p_header) { $v_result=1; // ----- Store the offset position of the file $p_header['offset'] = ftell($this->zip_fd); // ----- Transform UNIX mtime to DOS format mdate/mtime $v_date = getdate($p_header['mtime']); $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; // ----- Packed data $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len']); // ----- Write the first 148 bytes of the header in the archive fputs($this->zip_fd, $v_binary_data, 30); // ----- Write the variable fields if (strlen($p_header['stored_filename']) != 0) { fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); } if ($p_header['extra_len'] != 0) { fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privWriteCentralFileHeader() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privWriteCentralFileHeader(&$p_header) { $v_result=1; // TBC //for(reset($p_header); $key = key($p_header); next($p_header)) { //} // ----- Transform UNIX mtime to DOS format mdate/mtime $v_date = getdate($p_header['mtime']); $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; // ----- Packed data $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, $p_header['version'], $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len'], $p_header['comment_len'], $p_header['disk'], $p_header['internal'], $p_header['external'], $p_header['offset']); // ----- Write the 42 bytes of the header in the zip file fputs($this->zip_fd, $v_binary_data, 46); // ----- Write the variable fields if (strlen($p_header['stored_filename']) != 0) { fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); } if ($p_header['extra_len'] != 0) { fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); } if ($p_header['comment_len'] != 0) { fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privWriteCentralHeader() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) { $v_result=1; // ----- Packed data $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, $p_nb_entries, $p_size, $p_offset, strlen($p_comment)); // ----- Write the 22 bytes of the header in the zip file fputs($this->zip_fd, $v_binary_data, 22); // ----- Write the variable fields if (strlen($p_comment) != 0) { fputs($this->zip_fd, $p_comment, strlen($p_comment)); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privList() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privList(&$p_list) { $v_result=1; // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Open the zip file if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) { // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); // ----- Return return PclZip::errorCode(); } // ----- Read the central directory informations $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Go to beginning of Central Dir @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_central_dir['offset'])) { $this->privSwapBackMagicQuotes(); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return return PclZip::errorCode(); } // ----- Read each entry for ($i=0; $i<$v_central_dir['entries']; $i++) { // ----- Read the file header if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) { $this->privSwapBackMagicQuotes(); return $v_result; } $v_header['index'] = $i; // ----- Get the only interesting attributes $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); unset($v_header); } // ----- Close the zip file $this->privCloseFd(); // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privConvertHeader2FileInfo() // Description : // This function takes the file informations from the central directory // entries and extract the interesting parameters that will be given back. // The resulting file infos are set in the array $p_info // $p_info['filename'] : Filename with full path. Given by user (add), // extracted in the filesystem (extract). // $p_info['stored_filename'] : Stored filename in the archive. // $p_info['size'] = Size of the file. // $p_info['compressed_size'] = Compressed size of the file. // $p_info['mtime'] = Last modification date of the file. // $p_info['comment'] = Comment associated with the file. // $p_info['folder'] = true/false : indicates if the entry is a folder or not. // $p_info['status'] = status of the action on the file. // $p_info['crc'] = CRC of the file content. // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privConvertHeader2FileInfo($p_header, &$p_info) { $v_result=1; // ----- Get the interesting attributes $v_temp_path = PclZipUtilPathReduction($p_header['filename']); $p_info['filename'] = $v_temp_path; $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']); $p_info['stored_filename'] = $v_temp_path; $p_info['size'] = $p_header['size']; $p_info['compressed_size'] = $p_header['compressed_size']; $p_info['mtime'] = $p_header['mtime']; $p_info['comment'] = $p_header['comment']; $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); $p_info['index'] = $p_header['index']; $p_info['status'] = $p_header['status']; $p_info['crc'] = $p_header['crc']; // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privExtractByRule() // Description : // Extract a file or directory depending of rules (by index, by name, ...) // Parameters : // $p_file_list : An array where will be placed the properties of each // extracted file // $p_path : Path to add while writing the extracted files // $p_remove_path : Path to remove (from the file memorized path) while writing the // extracted files. If the path does not match the file path, // the file is extracted with its memorized path. // $p_remove_path does not apply to 'list' mode. // $p_path and $p_remove_path are commulative. // Return Values : // 1 on success,0 or less on error (see error code list) // -------------------------------------------------------------------------------- function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) { $v_result=1; // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Check the path if ( ($p_path == "") || ( (substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../") && (substr($p_path,1,2)!=":/"))) $p_path = "./".$p_path; // ----- Reduce the path last (and duplicated) '/' if (($p_path != "./") && ($p_path != "/")) { // ----- Look for the path end '/' while (substr($p_path, -1) == "/") { $p_path = substr($p_path, 0, strlen($p_path)-1); } } // ----- Look for path to remove format (should end by /) if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) { $p_remove_path .= '/'; } $p_remove_path_size = strlen($p_remove_path); // ----- Open the zip file if (($v_result = $this->privOpenFd('rb')) != 1) { $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Read the central directory informations $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { // ----- Close the zip file $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Start at beginning of Central Dir $v_pos_entry = $v_central_dir['offset']; // ----- Read each entry $j_start = 0; for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) { // ----- Read next Central dir entry @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_pos_entry)) { // ----- Close the zip file $this->privCloseFd(); $this->privSwapBackMagicQuotes(); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return return PclZip::errorCode(); } // ----- Read the file header $v_header = array(); if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) { // ----- Close the zip file $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Store the index $v_header['index'] = $i; // ----- Store the file position $v_pos_entry = ftell($this->zip_fd); // ----- Look for the specific extract rules $v_extract = false; // ----- Look for extract by name rule if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { // ----- Look if the filename is in the list for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { // ----- Look for a directory if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { // ----- Look if the directory is in the filename path if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { $v_extract = true; } } // ----- Look for a filename elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { $v_extract = true; } } } // ----- Look for extract by ereg rule // ereg() is deprecated with PHP 5.3 /* else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { $v_extract = true; } } */ // ----- Look for extract by preg rule else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { $v_extract = true; } } // ----- Look for extract by index rule else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { // ----- Look if the index is in the list for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { $v_extract = true; } if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { $j_start = $j+1; } if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { break; } } } // ----- Look for no rule, which means extract all the archive else { $v_extract = true; } // ----- Check compression method if ( ($v_extract) && ( ($v_header['compression'] != 8) && ($v_header['compression'] != 0))) { $v_header['status'] = 'unsupported_compression'; // ----- Look for PCLZIP_OPT_STOP_ON_ERROR if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, "Filename '".$v_header['stored_filename']."' is " ."compressed by an unsupported compression " ."method (".$v_header['compression'].") "); return PclZip::errorCode(); } } // ----- Check encrypted files if (($v_extract) && (($v_header['flag'] & 1) == 1)) { $v_header['status'] = 'unsupported_encryption'; // ----- Look for PCLZIP_OPT_STOP_ON_ERROR if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, "Unsupported encryption for " ." filename '".$v_header['stored_filename'] ."'"); return PclZip::errorCode(); } } // ----- Look for real extraction if (($v_extract) && ($v_header['status'] != 'ok')) { $v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++]); if ($v_result != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } $v_extract = false; } // ----- Look for real extraction if ($v_extract) { // ----- Go to the file position @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_header['offset'])) { // ----- Close the zip file $this->privCloseFd(); $this->privSwapBackMagicQuotes(); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return return PclZip::errorCode(); } // ----- Look for extraction as string if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { $v_string = ''; // ----- Extracting the file $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options); if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result1; } // ----- Get the only interesting attributes if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) { // ----- Close the zip file $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Set the file content $p_file_list[$v_nb_extracted]['content'] = $v_string; // ----- Next extracted file $v_nb_extracted++; // ----- Look for user callback abort if ($v_result1 == 2) { break; } } // ----- Look for extraction in standard output elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { // ----- Extracting the file in standard output $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result1; } // ----- Get the only interesting attributes if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Look for user callback abort if ($v_result1 == 2) { break; } } // ----- Look for normal extraction else { // ----- Extracting the file $v_result1 = $this->privExtractFile($v_header, $p_path, $p_remove_path, $p_remove_all_path, $p_options); if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result1; } // ----- Get the only interesting attributes if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { // ----- Close the zip file $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } // ----- Look for user callback abort if ($v_result1 == 2) { break; } } } } // ----- Close the zip file $this->privCloseFd(); $this->privSwapBackMagicQuotes(); // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privExtractFile() // Description : // Parameters : // Return Values : // // 1 : ... ? // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback // -------------------------------------------------------------------------------- function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) { $v_result=1; // ----- Read the file header if (($v_result = $this->privReadFileHeader($v_header)) != 1) { // ----- Return return $v_result; } // ----- Check that the file header is coherent with $p_entry info if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { // TBC } // ----- Look for all path to remove if ($p_remove_all_path == true) { // ----- Look for folder entry that not need to be extracted if (($p_entry['external']&0x00000010)==0x00000010) { $p_entry['status'] = "filtered"; return $v_result; } // ----- Get the basename of the path $p_entry['filename'] = basename($p_entry['filename']); } // ----- Look for path to remove else if ($p_remove_path != "") { if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) { // ----- Change the file status $p_entry['status'] = "filtered"; // ----- Return return $v_result; } $p_remove_path_size = strlen($p_remove_path); if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) { // ----- Remove the path $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); } } // ----- Add the path if ($p_path != '') { $p_entry['filename'] = $p_path."/".$p_entry['filename']; } // ----- Check a base_dir_restriction if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { $v_inclusion = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], $p_entry['filename']); if ($v_inclusion == 0) { PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, "Filename '".$p_entry['filename']."' is " ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); return PclZip::errorCode(); } } // ----- Look for pre-extract callback if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { // ----- Generate a local information $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); if ($v_result == 0) { // ----- Change the file status $p_entry['status'] = "skipped"; $v_result = 1; } // ----- Look for abort result if ($v_result == 2) { // ----- This status is internal and will be changed in 'skipped' $p_entry['status'] = "aborted"; $v_result = PCLZIP_ERR_USER_ABORTED; } // ----- Update the informations // Only some fields can be modified $p_entry['filename'] = $v_local_header['filename']; } // ----- Look if extraction should be done if ($p_entry['status'] == 'ok') { // ----- Look for specific actions while the file exist if (file_exists($p_entry['filename'])) { // ----- Look if file is a directory if (is_dir($p_entry['filename'])) { // ----- Change the file status $p_entry['status'] = "already_a_directory"; // ----- Look for PCLZIP_OPT_STOP_ON_ERROR // For historical reason first PclZip implementation does not stop // when this kind of error occurs. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, "Filename '".$p_entry['filename']."' is " ."already used by an existing directory"); return PclZip::errorCode(); } } // ----- Look if file is write protected else if (!is_writeable($p_entry['filename'])) { // ----- Change the file status $p_entry['status'] = "write_protected"; // ----- Look for PCLZIP_OPT_STOP_ON_ERROR // For historical reason first PclZip implementation does not stop // when this kind of error occurs. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Filename '".$p_entry['filename']."' exists " ."and is write protected"); return PclZip::errorCode(); } } // ----- Look if the extracted file is older else if (filemtime($p_entry['filename']) > $p_entry['mtime']) { // ----- Change the file status if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { } else { $p_entry['status'] = "newer_exist"; // ----- Look for PCLZIP_OPT_STOP_ON_ERROR // For historical reason first PclZip implementation does not stop // when this kind of error occurs. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Newer version of '".$p_entry['filename']."' exists " ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); return PclZip::errorCode(); } } } else { } } // ----- Check the directory availability and create it if necessary else { if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) $v_dir_to_check = $p_entry['filename']; else if (!strstr($p_entry['filename'], "/")) $v_dir_to_check = ""; else $v_dir_to_check = dirname($p_entry['filename']); if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { // ----- Change the file status $p_entry['status'] = "path_creation_fail"; // ----- Return //return $v_result; $v_result = 1; } } } // ----- Look if extraction should be done if ($p_entry['status'] == 'ok') { // ----- Do the extraction (if not a folder) if (!(($p_entry['external']&0x00000010)==0x00000010)) { // ----- Look for not compressed file if ($p_entry['compression'] == 0) { // ----- Opening destination file if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { // ----- Change the file status $p_entry['status'] = "write_error"; // ----- Return return $v_result; } // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks $v_size = $p_entry['compressed_size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($this->zip_fd, $v_read_size); /* Try to speed up the code $v_binary_data = pack('a'.$v_read_size, $v_buffer); @fwrite($v_dest_file, $v_binary_data, $v_read_size); */ @fwrite($v_dest_file, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Closing the destination file fclose($v_dest_file); // ----- Change the file mtime touch($p_entry['filename'], $p_entry['mtime']); } else { // ----- TBC // Need to be finished if (($p_entry['flag'] & 1) == 1) { PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); return PclZip::errorCode(); } // ----- Look for using temporary file to unzip if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); if ($v_result < PCLZIP_ERR_NO_ERROR) { return $v_result; } } // ----- Look for extract in memory else { // ----- Read the compressed file in a buffer (one shot) $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); // ----- Decompress the file $v_file_content = @gzinflate($v_buffer); unset($v_buffer); if ($v_file_content === FALSE) { // ----- Change the file status // TBC $p_entry['status'] = "error"; return $v_result; } // ----- Opening destination file if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { // ----- Change the file status $p_entry['status'] = "write_error"; return $v_result; } // ----- Write the uncompressed data @fwrite($v_dest_file, $v_file_content, $p_entry['size']); unset($v_file_content); // ----- Closing the destination file @fclose($v_dest_file); } // ----- Change the file mtime @touch($p_entry['filename'], $p_entry['mtime']); } // ----- Look for chmod option if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { // ----- Change the mode of the file @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); } } } // ----- Change abort status if ($p_entry['status'] == "aborted") { $p_entry['status'] = "skipped"; } // ----- Look for post-extract callback elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { // ----- Generate a local information $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); // ----- Look for abort result if ($v_result == 2) { $v_result = PCLZIP_ERR_USER_ABORTED; } } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privExtractFileUsingTempFile() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privExtractFileUsingTempFile(&$p_entry, &$p_options) { $v_result=1; // ----- Creates a temporary file $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { fclose($v_file); PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); return PclZip::errorCode(); } // ----- Write gz file format header $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); @fwrite($v_dest_file, $v_binary_data, 10); // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks $v_size = $p_entry['compressed_size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($this->zip_fd, $v_read_size); //$v_binary_data = pack('a'.$v_read_size, $v_buffer); @fwrite($v_dest_file, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Write gz file format footer $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']); @fwrite($v_dest_file, $v_binary_data, 8); // ----- Close the temporary file @fclose($v_dest_file); // ----- Opening destination file if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { $p_entry['status'] = "write_error"; return $v_result; } // ----- Open the temporary gz file if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { @fclose($v_dest_file); $p_entry['status'] = "read_error"; PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); return PclZip::errorCode(); } // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks $v_size = $p_entry['size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @gzread($v_src_file, $v_read_size); //$v_binary_data = pack('a'.$v_read_size, $v_buffer); @fwrite($v_dest_file, $v_buffer, $v_read_size); $v_size -= $v_read_size; } @fclose($v_dest_file); @gzclose($v_src_file); // ----- Delete the temporary file @unlink($v_gzip_temp_name); // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privExtractFileInOutput() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privExtractFileInOutput(&$p_entry, &$p_options) { $v_result=1; // ----- Read the file header if (($v_result = $this->privReadFileHeader($v_header)) != 1) { return $v_result; } // ----- Check that the file header is coherent with $p_entry info if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { // TBC } // ----- Look for pre-extract callback if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { // ----- Generate a local information $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); if ($v_result == 0) { // ----- Change the file status $p_entry['status'] = "skipped"; $v_result = 1; } // ----- Look for abort result if ($v_result == 2) { // ----- This status is internal and will be changed in 'skipped' $p_entry['status'] = "aborted"; $v_result = PCLZIP_ERR_USER_ABORTED; } // ----- Update the informations // Only some fields can be modified $p_entry['filename'] = $v_local_header['filename']; } // ----- Trace // ----- Look if extraction should be done if ($p_entry['status'] == 'ok') { // ----- Do the extraction (if not a folder) if (!(($p_entry['external']&0x00000010)==0x00000010)) { // ----- Look for not compressed file if ($p_entry['compressed_size'] == $p_entry['size']) { // ----- Read the file in a buffer (one shot) $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); // ----- Send the file to the output echo $v_buffer; unset($v_buffer); } else { // ----- Read the compressed file in a buffer (one shot) $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); // ----- Decompress the file $v_file_content = gzinflate($v_buffer); unset($v_buffer); // ----- Send the file to the output echo $v_file_content; unset($v_file_content); } } } // ----- Change abort status if ($p_entry['status'] == "aborted") { $p_entry['status'] = "skipped"; } // ----- Look for post-extract callback elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { // ----- Generate a local information $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); // ----- Look for abort result if ($v_result == 2) { $v_result = PCLZIP_ERR_USER_ABORTED; } } return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privExtractFileAsString() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) { $v_result=1; // ----- Read the file header $v_header = array(); if (($v_result = $this->privReadFileHeader($v_header)) != 1) { // ----- Return return $v_result; } // ----- Check that the file header is coherent with $p_entry info if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { // TBC } // ----- Look for pre-extract callback if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { // ----- Generate a local information $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); if ($v_result == 0) { // ----- Change the file status $p_entry['status'] = "skipped"; $v_result = 1; } // ----- Look for abort result if ($v_result == 2) { // ----- This status is internal and will be changed in 'skipped' $p_entry['status'] = "aborted"; $v_result = PCLZIP_ERR_USER_ABORTED; } // ----- Update the informations // Only some fields can be modified $p_entry['filename'] = $v_local_header['filename']; } // ----- Look if extraction should be done if ($p_entry['status'] == 'ok') { // ----- Do the extraction (if not a folder) if (!(($p_entry['external']&0x00000010)==0x00000010)) { // ----- Look for not compressed file // if ($p_entry['compressed_size'] == $p_entry['size']) if ($p_entry['compression'] == 0) { // ----- Reading the file $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); } else { // ----- Reading the file $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); // ----- Decompress the file if (($p_string = @gzinflate($v_data)) === FALSE) { // TBC } } // ----- Trace } else { // TBC : error : can not extract a folder in a string } } // ----- Change abort status if ($p_entry['status'] == "aborted") { $p_entry['status'] = "skipped"; } // ----- Look for post-extract callback elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { // ----- Generate a local information $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); // ----- Swap the content to header $v_local_header['content'] = $p_string; $p_string = ''; // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); // ----- Swap back the content to header $p_string = $v_local_header['content']; unset($v_local_header['content']); // ----- Look for abort result if ($v_result == 2) { $v_result = PCLZIP_ERR_USER_ABORTED; } } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privReadFileHeader() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privReadFileHeader(&$p_header) { $v_result=1; // ----- Read the 4 bytes signature $v_binary_data = @fread($this->zip_fd, 4); $v_data = unpack('Vid', $v_binary_data); // ----- Check signature if ($v_data['id'] != 0x04034b50) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); // ----- Return return PclZip::errorCode(); } // ----- Read the first 42 bytes of the header $v_binary_data = fread($this->zip_fd, 26); // ----- Look for invalid block size if (strlen($v_binary_data) != 26) { $p_header['filename'] = ""; $p_header['status'] = "invalid_header"; // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); // ----- Return return PclZip::errorCode(); } // ----- Extract the values $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); // ----- Get filename $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); // ----- Get extra_fields if ($v_data['extra_len'] != 0) { $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); } else { $p_header['extra'] = ''; } // ----- Extract properties $p_header['version_extracted'] = $v_data['version']; $p_header['compression'] = $v_data['compression']; $p_header['size'] = $v_data['size']; $p_header['compressed_size'] = $v_data['compressed_size']; $p_header['crc'] = $v_data['crc']; $p_header['flag'] = $v_data['flag']; $p_header['filename_len'] = $v_data['filename_len']; // ----- Recuperate date in UNIX format $p_header['mdate'] = $v_data['mdate']; $p_header['mtime'] = $v_data['mtime']; if ($p_header['mdate'] && $p_header['mtime']) { // ----- Extract time $v_hour = ($p_header['mtime'] & 0xF800) >> 11; $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; $v_seconde = ($p_header['mtime'] & 0x001F)*2; // ----- Extract date $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; $v_month = ($p_header['mdate'] & 0x01E0) >> 5; $v_day = $p_header['mdate'] & 0x001F; // ----- Get UNIX date format $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); } else { $p_header['mtime'] = time(); } // TBC //for(reset($v_data); $key = key($v_data); next($v_data)) { //} // ----- Set the stored filename $p_header['stored_filename'] = $p_header['filename']; // ----- Set the status field $p_header['status'] = "ok"; // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privReadCentralFileHeader() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privReadCentralFileHeader(&$p_header) { $v_result=1; // ----- Read the 4 bytes signature $v_binary_data = @fread($this->zip_fd, 4); $v_data = unpack('Vid', $v_binary_data); // ----- Check signature if ($v_data['id'] != 0x02014b50) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); // ----- Return return PclZip::errorCode(); } // ----- Read the first 42 bytes of the header $v_binary_data = fread($this->zip_fd, 42); // ----- Look for invalid block size if (strlen($v_binary_data) != 42) { $p_header['filename'] = ""; $p_header['status'] = "invalid_header"; // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); // ----- Return return PclZip::errorCode(); } // ----- Extract the values $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); // ----- Get filename if ($p_header['filename_len'] != 0) $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); else $p_header['filename'] = ''; // ----- Get extra if ($p_header['extra_len'] != 0) $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); else $p_header['extra'] = ''; // ----- Get comment if ($p_header['comment_len'] != 0) $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); else $p_header['comment'] = ''; // ----- Extract properties // ----- Recuperate date in UNIX format //if ($p_header['mdate'] && $p_header['mtime']) // TBC : bug : this was ignoring time with 0/0/0 if (1) { // ----- Extract time $v_hour = ($p_header['mtime'] & 0xF800) >> 11; $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; $v_seconde = ($p_header['mtime'] & 0x001F)*2; // ----- Extract date $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; $v_month = ($p_header['mdate'] & 0x01E0) >> 5; $v_day = $p_header['mdate'] & 0x001F; // ----- Get UNIX date format $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); } else { $p_header['mtime'] = time(); } // ----- Set the stored filename $p_header['stored_filename'] = $p_header['filename']; // ----- Set default status to ok $p_header['status'] = 'ok'; // ----- Look if it is a directory if (substr($p_header['filename'], -1) == '/') { //$p_header['external'] = 0x41FF0010; $p_header['external'] = 0x00000010; } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privCheckFileHeaders() // Description : // Parameters : // Return Values : // 1 on success, // 0 on error; // -------------------------------------------------------------------------------- function privCheckFileHeaders(&$p_local_header, &$p_central_header) { $v_result=1; // ----- Check the static values // TBC if ($p_local_header['filename'] != $p_central_header['filename']) { } if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { } if ($p_local_header['flag'] != $p_central_header['flag']) { } if ($p_local_header['compression'] != $p_central_header['compression']) { } if ($p_local_header['mtime'] != $p_central_header['mtime']) { } if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { } // ----- Look for flag bit 3 if (($p_local_header['flag'] & 8) == 8) { $p_local_header['size'] = $p_central_header['size']; $p_local_header['compressed_size'] = $p_central_header['compressed_size']; $p_local_header['crc'] = $p_central_header['crc']; } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privReadEndCentralDir() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privReadEndCentralDir(&$p_central_dir) { $v_result=1; // ----- Go to the end of the zip file $v_size = filesize($this->zipname); @fseek($this->zip_fd, $v_size); if (@ftell($this->zip_fd) != $v_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); // ----- Return return PclZip::errorCode(); } // ----- First try : look if this is an archive with no commentaries (most of the time) // in this case the end of central dir is at 22 bytes of the file end $v_found = 0; if ($v_size > 26) { @fseek($this->zip_fd, $v_size-22); if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); // ----- Return return PclZip::errorCode(); } // ----- Read for bytes $v_binary_data = @fread($this->zip_fd, 4); $v_data = @unpack('Vid', $v_binary_data); // ----- Check signature if ($v_data['id'] == 0x06054b50) { $v_found = 1; } $v_pos = ftell($this->zip_fd); } // ----- Go back to the maximum possible size of the Central Dir End Record if (!$v_found) { $v_maximum_size = 65557; // 0xFFFF + 22; if ($v_maximum_size > $v_size) $v_maximum_size = $v_size; @fseek($this->zip_fd, $v_size-$v_maximum_size); if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); // ----- Return return PclZip::errorCode(); } // ----- Read byte per byte in order to find the signature $v_pos = ftell($this->zip_fd); $v_bytes = 0x00000000; while ($v_pos < $v_size) { // ----- Read a byte $v_byte = @fread($this->zip_fd, 1); // ----- Add the byte //$v_bytes = ($v_bytes << 8) | Ord($v_byte); // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); // ----- Compare the bytes if ($v_bytes == 0x504b0506) { $v_pos++; break; } $v_pos++; } // ----- Look if not found end of central dir if ($v_pos == $v_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); // ----- Return return PclZip::errorCode(); } } // ----- Read the first 18 bytes of the header $v_binary_data = fread($this->zip_fd, 18); // ----- Look for invalid block size if (strlen($v_binary_data) != 18) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); // ----- Return return PclZip::errorCode(); } // ----- Extract the values $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); // ----- Check the global size if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { // ----- Removed in release 2.2 see readme file // The check of the file size is a little too strict. // Some bugs where found when a zip is encrypted/decrypted with 'crypt'. // While decrypted, zip has training 0 bytes if (0) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'The central dir is not at the end of the archive.' .' Some trailing bytes exists after the archive.'); // ----- Return return PclZip::errorCode(); } } // ----- Get comment if ($v_data['comment_size'] != 0) { $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); } else $p_central_dir['comment'] = ''; $p_central_dir['entries'] = $v_data['entries']; $p_central_dir['disk_entries'] = $v_data['disk_entries']; $p_central_dir['offset'] = $v_data['offset']; $p_central_dir['size'] = $v_data['size']; $p_central_dir['disk'] = $v_data['disk']; $p_central_dir['disk_start'] = $v_data['disk_start']; // TBC //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { //} // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privDeleteByRule() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privDeleteByRule(&$p_result_list, &$p_options) { $v_result=1; $v_list_detail = array(); // ----- Open the zip file if (($v_result=$this->privOpenFd('rb')) != 1) { // ----- Return return $v_result; } // ----- Read the central directory informations $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); return $v_result; } // ----- Go to beginning of File @rewind($this->zip_fd); // ----- Scan all the files // ----- Start at beginning of Central Dir $v_pos_entry = $v_central_dir['offset']; @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_pos_entry)) { // ----- Close the zip file $this->privCloseFd(); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return return PclZip::errorCode(); } // ----- Read each entry $v_header_list = array(); $j_start = 0; for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) { // ----- Read the file header $v_header_list[$v_nb_extracted] = array(); if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) { // ----- Close the zip file $this->privCloseFd(); return $v_result; } // ----- Store the index $v_header_list[$v_nb_extracted]['index'] = $i; // ----- Look for the specific extract rules $v_found = false; // ----- Look for extract by name rule if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { // ----- Look if the filename is in the list for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { // ----- Look for a directory if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { // ----- Look if the directory is in the filename path if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { $v_found = true; } elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { $v_found = true; } } // ----- Look for a filename elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { $v_found = true; } } } // ----- Look for extract by ereg rule // ereg() is deprecated with PHP 5.3 /* else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { $v_found = true; } } */ // ----- Look for extract by preg rule else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { $v_found = true; } } // ----- Look for extract by index rule else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { // ----- Look if the index is in the list for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { $v_found = true; } if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { $j_start = $j+1; } if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { break; } } } else { $v_found = true; } // ----- Look for deletion if ($v_found) { unset($v_header_list[$v_nb_extracted]); } else { $v_nb_extracted++; } } // ----- Look if something need to be deleted if ($v_nb_extracted > 0) { // ----- Creates a temporay file $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; // ----- Creates a temporary zip archive $v_temp_zip = new PclZip($v_zip_temp_name); // ----- Open the temporary zip file in write mode if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { $this->privCloseFd(); // ----- Return return $v_result; } // ----- Look which file need to be kept for ($i=0; $i<sizeof($v_header_list); $i++) { // ----- Calculate the position of the header @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { // ----- Close the zip file $this->privCloseFd(); $v_temp_zip->privCloseFd(); @unlink($v_zip_temp_name); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return return PclZip::errorCode(); } // ----- Read the file header $v_local_header = array(); if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { // ----- Close the zip file $this->privCloseFd(); $v_temp_zip->privCloseFd(); @unlink($v_zip_temp_name); // ----- Return return $v_result; } // ----- Check that local file header is same as central file header if ($this->privCheckFileHeaders($v_local_header, $v_header_list[$i]) != 1) { // TBC } unset($v_local_header); // ----- Write the file header if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { // ----- Close the zip file $this->privCloseFd(); $v_temp_zip->privCloseFd(); @unlink($v_zip_temp_name); // ----- Return return $v_result; } // ----- Read/write the data block if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { // ----- Close the zip file $this->privCloseFd(); $v_temp_zip->privCloseFd(); @unlink($v_zip_temp_name); // ----- Return return $v_result; } } // ----- Store the offset of the central dir $v_offset = @ftell($v_temp_zip->zip_fd); // ----- Re-Create the Central Dir files header for ($i=0; $i<sizeof($v_header_list); $i++) { // ----- Create the file header if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { $v_temp_zip->privCloseFd(); $this->privCloseFd(); @unlink($v_zip_temp_name); // ----- Return return $v_result; } // ----- Transform the header to a 'usable' info $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); } // ----- Zip file comment $v_comment = ''; if (isset($p_options[PCLZIP_OPT_COMMENT])) { $v_comment = $p_options[PCLZIP_OPT_COMMENT]; } // ----- Calculate the size of the central header $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; // ----- Create the central dir footer if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { // ----- Reset the file list unset($v_header_list); $v_temp_zip->privCloseFd(); $this->privCloseFd(); @unlink($v_zip_temp_name); // ----- Return return $v_result; } // ----- Close $v_temp_zip->privCloseFd(); $this->privCloseFd(); // ----- Delete the zip file // TBC : I should test the result ... @unlink($this->zipname); // ----- Rename the temporary file // TBC : I should test the result ... //@rename($v_zip_temp_name, $this->zipname); PclZipUtilRename($v_zip_temp_name, $this->zipname); // ----- Destroy the temporary archive unset($v_temp_zip); } // ----- Remove every files : reset the file else if ($v_central_dir['entries'] != 0) { $this->privCloseFd(); if (($v_result = $this->privOpenFd('wb')) != 1) { return $v_result; } if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { return $v_result; } $this->privCloseFd(); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privDirCheck() // Description : // Check if a directory exists, if not it creates it and all the parents directory // which may be useful. // Parameters : // $p_dir : Directory path to check. // Return Values : // 1 : OK // -1 : Unable to create directory // -------------------------------------------------------------------------------- function privDirCheck($p_dir, $p_is_dir=false) { $v_result = 1; // ----- Remove the final '/' if (($p_is_dir) && (substr($p_dir, -1)=='/')) { $p_dir = substr($p_dir, 0, strlen($p_dir)-1); } // ----- Check the directory availability if ((is_dir($p_dir)) || ($p_dir == "")) { return 1; } // ----- Extract parent directory $p_parent_dir = dirname($p_dir); // ----- Just a check if ($p_parent_dir != $p_dir) { // ----- Look for parent directory if ($p_parent_dir != "") { if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) { return $v_result; } } } // ----- Create the directory if (!@mkdir($p_dir, 0777)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); // ----- Return return PclZip::errorCode(); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privMerge() // Description : // If $p_archive_to_add does not exist, the function exit with a success result. // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privMerge(&$p_archive_to_add) { $v_result=1; // ----- Look if the archive_to_add exists if (!is_file($p_archive_to_add->zipname)) { // ----- Nothing to merge, so merge is a success $v_result = 1; // ----- Return return $v_result; } // ----- Look if the archive exists if (!is_file($this->zipname)) { // ----- Do a duplicate $v_result = $this->privDuplicate($p_archive_to_add->zipname); // ----- Return return $v_result; } // ----- Open the zip file if (($v_result=$this->privOpenFd('rb')) != 1) { // ----- Return return $v_result; } // ----- Read the central directory informations $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); return $v_result; } // ----- Go to beginning of File @rewind($this->zip_fd); // ----- Open the archive_to_add file if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) { $this->privCloseFd(); // ----- Return return $v_result; } // ----- Read the central directory informations $v_central_dir_to_add = array(); if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) { $this->privCloseFd(); $p_archive_to_add->privCloseFd(); return $v_result; } // ----- Go to beginning of File @rewind($p_archive_to_add->zip_fd); // ----- Creates a temporay file $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; // ----- Open the temporary file in write mode if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) { $this->privCloseFd(); $p_archive_to_add->privCloseFd(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); // ----- Return return PclZip::errorCode(); } // ----- Copy the files from the archive to the temporary file // TBC : Here I should better append the file and go back to erase the central dir $v_size = $v_central_dir['offset']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Copy the files from the archive_to_add into the temporary file $v_size = $v_central_dir_to_add['offset']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Store the offset of the central dir $v_offset = @ftell($v_zip_temp_fd); // ----- Copy the block of file headers from the old archive $v_size = $v_central_dir['size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Copy the block of file headers from the archive_to_add $v_size = $v_central_dir_to_add['size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Merge the file comments $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; // ----- Calculate the size of the (new) central header $v_size = @ftell($v_zip_temp_fd)-$v_offset; // ----- Swap the file descriptor // Here is a trick : I swap the temporary fd with the zip fd, in order to use // the following methods on the temporary fil and not the real archive fd $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; // ----- Create the central dir footer if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) { $this->privCloseFd(); $p_archive_to_add->privCloseFd(); @fclose($v_zip_temp_fd); $this->zip_fd = null; // ----- Reset the file list unset($v_header_list); // ----- Return return $v_result; } // ----- Swap back the file descriptor $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; // ----- Close $this->privCloseFd(); $p_archive_to_add->privCloseFd(); // ----- Close the temporary file @fclose($v_zip_temp_fd); // ----- Delete the zip file // TBC : I should test the result ... @unlink($this->zipname); // ----- Rename the temporary file // TBC : I should test the result ... //@rename($v_zip_temp_name, $this->zipname); PclZipUtilRename($v_zip_temp_name, $this->zipname); // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privDuplicate() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privDuplicate($p_archive_filename) { $v_result=1; // ----- Look if the $p_archive_filename exists if (!is_file($p_archive_filename)) { // ----- Nothing to duplicate, so duplicate is a success. $v_result = 1; // ----- Return return $v_result; } // ----- Open the zip file if (($v_result=$this->privOpenFd('wb')) != 1) { // ----- Return return $v_result; } // ----- Open the temporary file in write mode if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) { $this->privCloseFd(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); // ----- Return return PclZip::errorCode(); } // ----- Copy the files from the archive to the temporary file // TBC : Here I should better append the file and go back to erase the central dir $v_size = filesize($p_archive_filename); while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($v_zip_temp_fd, $v_read_size); @fwrite($this->zip_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } // ----- Close $this->privCloseFd(); // ----- Close the temporary file @fclose($v_zip_temp_fd); // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privErrorLog() // Description : // Parameters : // -------------------------------------------------------------------------------- function privErrorLog($p_error_code=0, $p_error_string='') { if (PCLZIP_ERROR_EXTERNAL == 1) { PclError($p_error_code, $p_error_string); } else { $this->error_code = $p_error_code; $this->error_string = $p_error_string; } } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privErrorReset() // Description : // Parameters : // -------------------------------------------------------------------------------- function privErrorReset() { if (PCLZIP_ERROR_EXTERNAL == 1) { PclErrorReset(); } else { $this->error_code = 0; $this->error_string = ''; } } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privDisableMagicQuotes() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privDisableMagicQuotes() { $v_result=1; // ----- Look if function exists if ( (!function_exists("get_magic_quotes_runtime")) || (!function_exists("set_magic_quotes_runtime"))) { return $v_result; } // ----- Look if already done if ($this->magic_quotes_status != -1) { return $v_result; } // ----- Get and memorize the magic_quote value $this->magic_quotes_status = @get_magic_quotes_runtime(); // ----- Disable magic_quotes if ($this->magic_quotes_status == 1) { @set_magic_quotes_runtime(0); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : privSwapBackMagicQuotes() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privSwapBackMagicQuotes() { $v_result=1; // ----- Look if function exists if ( (!function_exists("get_magic_quotes_runtime")) || (!function_exists("set_magic_quotes_runtime"))) { return $v_result; } // ----- Look if something to do if ($this->magic_quotes_status != -1) { return $v_result; } // ----- Swap back magic_quotes if ($this->magic_quotes_status == 1) { @set_magic_quotes_runtime($this->magic_quotes_status); } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- } // End of class // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclZipUtilPathReduction() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function PclZipUtilPathReduction($p_dir) { $v_result = ""; // ----- Look for not empty path if ($p_dir != "") { // ----- Explode path by directory names $v_list = explode("/", $p_dir); // ----- Study directories from last to first $v_skip = 0; for ($i=sizeof($v_list)-1; $i>=0; $i--) { // ----- Look for current path if ($v_list[$i] == ".") { // ----- Ignore this directory // Should be the first $i=0, but no check is done } else if ($v_list[$i] == "..") { $v_skip++; } else if ($v_list[$i] == "") { // ----- First '/' i.e. root slash if ($i == 0) { $v_result = "/".$v_result; if ($v_skip > 0) { // ----- It is an invalid path, so the path is not modified // TBC $v_result = $p_dir; $v_skip = 0; } } // ----- Last '/' i.e. indicates a directory else if ($i == (sizeof($v_list)-1)) { $v_result = $v_list[$i]; } // ----- Double '/' inside the path else { // ----- Ignore only the double '//' in path, // but not the first and last '/' } } else { // ----- Look for item to skip if ($v_skip > 0) { $v_skip--; } else { $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); } } } // ----- Look for skip if ($v_skip > 0) { while ($v_skip > 0) { $v_result = '../'.$v_result; $v_skip--; } } } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclZipUtilPathInclusion() // Description : // This function indicates if the path $p_path is under the $p_dir tree. Or, // said in an other way, if the file or sub-dir $p_path is inside the dir // $p_dir. // The function indicates also if the path is exactly the same as the dir. // This function supports path with duplicated '/' like '//', but does not // support '.' or '..' statements. // Parameters : // Return Values : // 0 if $p_path is not inside directory $p_dir // 1 if $p_path is inside directory $p_dir // 2 if $p_path is exactly the same as $p_dir // -------------------------------------------------------------------------------- function PclZipUtilPathInclusion($p_dir, $p_path) { $v_result = 1; // ----- Look for path beginning by ./ if ( ($p_dir == '.') || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); } if ( ($p_path == '.') || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); } // ----- Explode dir and path by directory separator $v_list_dir = explode("/", $p_dir); $v_list_dir_size = sizeof($v_list_dir); $v_list_path = explode("/", $p_path); $v_list_path_size = sizeof($v_list_path); // ----- Study directories paths $i = 0; $j = 0; while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { // ----- Look for empty dir (path reduction) if ($v_list_dir[$i] == '') { $i++; continue; } if ($v_list_path[$j] == '') { $j++; continue; } // ----- Compare the items if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { $v_result = 0; } // ----- Next items $i++; $j++; } // ----- Look if everything seems to be the same if ($v_result) { // ----- Skip all the empty items while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { // ----- There are exactly the same $v_result = 2; } else if ($i < $v_list_dir_size) { // ----- The path is shorter than the dir $v_result = 0; } } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclZipUtilCopyBlock() // Description : // Parameters : // $p_mode : read/write compression mode // 0 : src & dest normal // 1 : src gzip, dest normal // 2 : src normal, dest gzip // 3 : src & dest gzip // Return Values : // -------------------------------------------------------------------------------- function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) { $v_result = 1; if ($p_mode==0) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($p_src, $v_read_size); @fwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } } else if ($p_mode==1) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @gzread($p_src, $v_read_size); @fwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } } else if ($p_mode==2) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($p_src, $v_read_size); @gzwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } } else if ($p_mode==3) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @gzread($p_src, $v_read_size); @gzwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclZipUtilRename() // Description : // This function tries to do a simple rename() function. If it fails, it // tries to copy the $p_src file in a new $p_dest file and then unlink the // first one. // Parameters : // $p_src : Old filename // $p_dest : New filename // Return Values : // 1 on success, 0 on failure. // -------------------------------------------------------------------------------- function PclZipUtilRename($p_src, $p_dest) { $v_result = 1; // ----- Try to rename the files if (!@rename($p_src, $p_dest)) { // ----- Try to copy & unlink the src if (!@copy($p_src, $p_dest)) { $v_result = 0; } else if (!@unlink($p_src)) { $v_result = 0; } } // ----- Return return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclZipUtilOptionText() // Description : // Translate option value in text. Mainly for debug purpose. // Parameters : // $p_option : the option value. // Return Values : // The option text value. // -------------------------------------------------------------------------------- function PclZipUtilOptionText($p_option) { $v_list = get_defined_constants(); for (reset($v_list); $v_key = key($v_list); next($v_list)) { $v_prefix = substr($v_key, 0, 10); if (( ($v_prefix == 'PCLZIP_OPT') || ($v_prefix == 'PCLZIP_CB_') || ($v_prefix == 'PCLZIP_ATT')) && ($v_list[$v_key] == $p_option)) { return $v_key; } } $v_result = 'Unknown'; return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclZipUtilTranslateWinPath() // Description : // Translate windows path by replacing '\' by '/' and optionally removing // drive letter. // Parameters : // $p_path : path to translate. // $p_remove_disk_letter : true | false // Return Values : // The path translated. // -------------------------------------------------------------------------------- function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) { if (stristr(php_uname(), 'windows')) { // ----- Look for potential disk letter if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { $p_path = substr($p_path, $v_position+1); } // ----- Change potential windows directory separator if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { $p_path = strtr($p_path, '\\', '/'); } } return $p_path; } // -------------------------------------------------------------------------------- ?>
01happy-blog
trunk/myblog/wp-admin/includes/class-pclzip.php
PHP
oos
195,618
<?php /** * Multisite Users List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_MS_Users_List_Table extends WP_List_Table { function ajax_user_can() { return current_user_can( 'manage_network_users' ); } function prepare_items() { global $usersearch, $role, $wpdb, $mode; $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; $users_per_page = $this->get_items_per_page( 'users_network_per_page' ); $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : ''; $paged = $this->get_pagenum(); $args = array( 'number' => $users_per_page, 'offset' => ( $paged-1 ) * $users_per_page, 'search' => $usersearch, 'blog_id' => 0, 'fields' => 'all_with_meta' ); if ( wp_is_large_network( 'users' ) ) $args['search'] = ltrim( $args['search'], '*' ); if ( $role == 'super' ) { $logins = implode( "', '", get_super_admins() ); $args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" ); } // If the network is large and a search is not being performed, show only the latest users with no paging in order // to avoid expensive count queries. if ( !$usersearch && wp_is_large_network( 'users' ) ) { if ( !isset($_REQUEST['orderby']) ) $_GET['orderby'] = $_REQUEST['orderby'] = 'id'; if ( !isset($_REQUEST['order']) ) $_GET['order'] = $_REQUEST['order'] = 'DESC'; $args['count_total'] = false; } if ( isset( $_REQUEST['orderby'] ) ) $args['orderby'] = $_REQUEST['orderby']; if ( isset( $_REQUEST['order'] ) ) $args['order'] = $_REQUEST['order']; $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; // Query the user IDs for this page $wp_user_search = new WP_User_Query( $args ); $this->items = $wp_user_search->get_results(); $this->set_pagination_args( array( 'total_items' => $wp_user_search->get_total(), 'per_page' => $users_per_page, ) ); } function get_bulk_actions() { $actions = array(); if ( current_user_can( 'delete_users' ) ) $actions['delete'] = __( 'Delete' ); $actions['spam'] = _x( 'Mark as Spam', 'user' ); $actions['notspam'] = _x( 'Not Spam', 'user' ); return $actions; } function no_items() { _e( 'No users found.' ); } function get_views() { global $wp_roles, $role; $total_users = get_user_count(); $super_admins = get_super_admins(); $total_admins = count( $super_admins ); $current_role = false; $class = $role != 'super' ? ' class="current"' : ''; $role_links = array(); $role_links['all'] = "<a href='" . network_admin_url('users.php') . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; $class = $role == 'super' ? ' class="current"' : ''; $role_links['super'] = "<a href='" . network_admin_url('users.php?role=super') . "'$class>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>'; return $role_links; } function pagination( $which ) { global $mode; parent::pagination ( $which ); if ( 'top' == $which ) $this->view_switcher( $mode ); } function get_columns() { $users_columns = array( 'cb' => '<input type="checkbox" />', 'username' => __( 'Username' ), 'name' => __( 'Name' ), 'email' => __( 'E-mail' ), 'registered' => _x( 'Registered', 'user' ), 'blogs' => __( 'Sites' ) ); $users_columns = apply_filters( 'wpmu_users_columns', $users_columns ); return $users_columns; } function get_sortable_columns() { return array( 'username' => 'login', 'name' => 'name', 'email' => 'email', 'registered' => 'id', ); } function display_rows() { global $current_site, $mode; $alt = ''; $super_admins = get_super_admins(); foreach ( $this->items as $user ) { $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); foreach ( $status_list as $status => $col ) { if ( $user->$status ) $alt .= " $col"; } ?> <tr class="<?php echo $alt; ?>"> <?php list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) : $class = "class='$column_name column-$column_name'"; $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; $attributes = "$class$style"; switch ( $column_name ) { case 'cb': ?> <th scope="row" class="check-column"> <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" /> </th> <?php break; case 'username': $avatar = get_avatar( $user->user_email, 32 ); if ( get_current_user_id() == $user->ID ) { $edit_link = esc_url( network_admin_url( 'profile.php' ) ); } else { $edit_link = esc_url( network_admin_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), 'user-edit.php?user_id=' . $user->ID ) ) ); } echo "<td $attributes>"; ?> <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a><?php if ( in_array( $user->user_login, $super_admins ) ) echo ' - ' . __( 'Super Admin' ); ?></strong> <br/> <?php $actions = array(); $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; } $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); echo $this->row_actions( $actions ); ?> </td> <?php break; case 'name': echo "<td $attributes>$user->first_name $user->last_name</td>"; break; case 'email': echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>"; break; case 'registered': if ( 'list' == $mode ) $date = 'Y/m/d'; else $date = 'Y/m/d \<\b\r \/\> g:i:s a'; echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>"; break; case 'blogs': $blogs = get_blogs_of_user( $user->ID, true ); echo "<td $attributes>"; if ( is_array( $blogs ) ) { foreach ( (array) $blogs as $key => $val ) { if ( !can_edit_network( $val->site_id ) ) continue; $path = ( $val->path == '/' ) ? '' : $val->path; echo '<span class="site-' . $val->site_id . '" >'; echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>'; echo ' <small class="row-actions">'; $actions = array(); $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>'; $class = ''; if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 ) $class .= 'site-spammed '; if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 ) $class .= 'site-mature '; if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 ) $class .= 'site-deleted '; if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 ) $class .= 'site-archived '; $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>'; $actions = apply_filters('ms_user_list_site_actions', $actions, $val->userblog_id); $i=0; $action_count = count( $actions ); foreach ( $actions as $action => $link ) { ++$i; ( $i == $action_count ) ? $sep = '' : $sep = ' | '; echo "<span class='$action'>$link$sep</span>"; } echo '</small></span><br/>'; } } ?> </td> <?php break; default: echo "<td $attributes>"; echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); echo "</td>"; break; } endforeach ?> </tr> <?php } } }
01happy-blog
trunk/myblog/wp-admin/includes/class-wp-ms-users-list-table.php
PHP
oos
8,832
<?php /** * Media Library List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Media_List_Table extends WP_List_Table { function __construct() { $this->detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] ); parent::__construct( array( 'plural' => 'media' ) ); } function ajax_user_can() { return current_user_can('upload_files'); } function prepare_items() { global $lost, $wpdb, $wp_query, $post_mime_types, $avail_post_mime_types; $q = $_REQUEST; if ( !empty( $lost ) ) $q['post__in'] = implode( ',', $lost ); list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $q ); $this->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status']; $this->set_pagination_args( array( 'total_items' => $wp_query->found_posts, 'total_pages' => $wp_query->max_num_pages, 'per_page' => $wp_query->query_vars['posts_per_page'], ) ); } function get_views() { global $wpdb, $post_mime_types, $avail_post_mime_types; $type_links = array(); $_num_posts = (array) wp_count_attachments(); $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; if ( !isset( $total_orphans ) ) $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" ); $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); foreach ( $matches as $type => $reals ) foreach ( $reals as $real ) $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real]; $class = ( empty($_GET['post_mime_type']) && !$this->detached && !isset($_GET['status']) ) ? ' class="current"' : ''; $type_links['all'] = "<a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>'; foreach ( $post_mime_types as $mime_type => $label ) { $class = ''; if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) continue; if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) $class = ' class="current"'; if ( !empty( $num_posts[$mime_type] ) ) $type_links[$mime_type] = "<a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>'; } $type_links['detached'] = '<a href="upload.php?detached=1"' . ( $this->detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>'; if ( !empty($_num_posts['trash']) ) $type_links['trash'] = '<a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>'; return $type_links; } function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete Permanently' ); if ( $this->detached ) $actions['attach'] = __( 'Attach to a post' ); return $actions; } function extra_tablenav( $which ) { ?> <div class="alignleft actions"> <?php if ( 'top' == $which && !is_singular() && !$this->detached && !$this->is_trash ) { $this->months_dropdown( 'attachment' ); do_action( 'restrict_manage_posts' ); submit_button( __( 'Filter' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) ); } if ( $this->detached ) { submit_button( __( 'Scan for lost attachments' ), 'secondary', 'find_detached', false ); } elseif ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) { submit_button( __( 'Empty Trash' ), 'button-secondary apply', 'delete_all', false ); } ?> </div> <?php } function current_action() { if ( isset( $_REQUEST['find_detached'] ) ) return 'find_detached'; if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) return 'attach'; if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) return 'delete_all'; return parent::current_action(); } function has_items() { return have_posts(); } function no_items() { _e( 'No media attachments found.' ); } function get_columns() { $posts_columns = array(); $posts_columns['cb'] = '<input type="checkbox" />'; $posts_columns['icon'] = ''; /* translators: column name */ $posts_columns['title'] = _x( 'File', 'column name' ); $posts_columns['author'] = __( 'Author' ); //$posts_columns['tags'] = _x( 'Tags', 'column name' ); /* translators: column name */ if ( !$this->detached ) { $posts_columns['parent'] = _x( 'Attached to', 'column name' ); if ( post_type_supports( 'attachment', 'comments' ) ) $posts_columns['comments'] = '<span class="vers"><img alt="' . esc_attr__( 'Comments' ) . '" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></span>'; } /* translators: column name */ $posts_columns['date'] = _x( 'Date', 'column name' ); $posts_columns = apply_filters( 'manage_media_columns', $posts_columns, $this->detached ); return $posts_columns; } function get_sortable_columns() { return array( 'title' => 'title', 'author' => 'author', 'parent' => 'parent', 'comments' => 'comment_count', 'date' => array( 'date', true ), ); } function display_rows() { global $post, $id; add_filter( 'the_title','esc_html' ); $alt = ''; while ( have_posts() ) : the_post(); $user_can_edit = current_user_can( 'edit_post', $post->ID ); if ( $this->is_trash && $post->post_status != 'trash' || !$this->is_trash && $post->post_status == 'trash' ) continue; $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other'; $att_title = _draft_or_post_title(); ?> <tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top"> <?php list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class='$column_name column-$column_name'"; $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; $attributes = $class . $style; switch ( $column_name ) { case 'cb': ?> <th scope="row" class="check-column"> <?php if ( $user_can_edit ) { ?> <input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /> <?php } ?> </th> <?php break; case 'icon': $attributes = 'class="column-icon media-icon"' . $style; ?> <td <?php echo $attributes ?>><?php if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) { if ( $this->is_trash || ! $user_can_edit ) { echo $thumb; } else { ?> <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>"> <?php echo $thumb; ?> </a> <?php } } ?> </td> <?php break; case 'title': ?> <td <?php echo $attributes ?>><strong> <?php if ( $this->is_trash || ! $user_can_edit ) { echo $att_title; } else { ?> <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>"> <?php echo $att_title; ?></a> <?php }; _media_states( $post ); ?></strong> <p> <?php if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) echo esc_html( strtoupper( $matches[1] ) ); else echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) ); ?> </p> <?php echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) ); ?> </td> <?php break; case 'author': ?> <td <?php echo $attributes ?>><?php the_author() ?></td> <?php break; case 'tags': ?> <td <?php echo $attributes ?>><?php $tags = get_the_tags(); if ( !empty( $tags ) ) { $out = array(); foreach ( $tags as $c ) $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "</a>"; echo join( ', ', $out ); } else { _e( 'No Tags' ); } ?> </td> <?php break; case 'desc': ?> <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td> <?php break; case 'date': if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) { $t_time = $h_time = __( 'Unpublished' ); } else { $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) ); $m_time = $post->post_date; $time = get_post_time( 'G', true, $post, false ); if ( ( abs( $t_diff = time() - $time ) ) < 86400 ) { if ( $t_diff < 0 ) $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) ); else $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); } else { $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); } } ?> <td <?php echo $attributes ?>><?php echo $h_time ?></td> <?php break; case 'parent': if ( $post->post_parent > 0 ) { if ( get_post( $post->post_parent ) ) { $title =_draft_or_post_title( $post->post_parent ); } ?> <td <?php echo $attributes ?>><strong> <?php if( current_user_can( 'edit_post', $post->post_parent ) ) { ?> <a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"> <?php echo $title ?></a><?php } else { echo $title; } ?></strong>, <?php echo get_the_time( __( 'Y/m/d' ) ); ?> </td> <?php } else { ?> <td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br /> <?php if( $user_can_edit ) {?> <a class="hide-if-no-js" onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' ); return false;" href="#the-list"> <?php _e( 'Attach' ); ?></a> <?php } ?></td> <?php } break; case 'comments': $attributes = 'class="comments column-comments num"' . $style; ?> <td <?php echo $attributes ?>> <div class="post-com-count-wrapper"> <?php $pending_comments = get_pending_comments_num( $post->ID ); $this->comments_bubble( $post->ID, $pending_comments ); ?> </div> </td> <?php break; default: ?> <td <?php echo $attributes ?>> <?php do_action( 'manage_media_custom_column', $column_name, $id ); ?> </td> <?php break; } } ?> </tr> <?php endwhile; } function _get_row_actions( $post, $att_title ) { $actions = array(); if ( $this->detached ) { if ( current_user_can( 'edit_post', $post->ID ) ) $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>'; if ( current_user_can( 'delete_post', $post->ID ) ) if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; } else { $delete_ays = !MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-attachment_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>"; } $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; if ( current_user_can( 'edit_post', $post->ID ) ) $actions['attach'] = '<a href="#the-list" onclick="findPosts.open( \'media[]\',\''.$post->ID.'\' );return false;" class="hide-if-no-js">'.__( 'Attach' ).'</a>'; } else { if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash ) $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>'; if ( current_user_can( 'delete_post', $post->ID ) ) { if ( $this->is_trash ) $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-attachment_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>"; elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; if ( $this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH ) { $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-attachment_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>"; } } if ( !$this->is_trash ) { $title =_draft_or_post_title( $post->post_parent ); $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; } } $actions = apply_filters( 'media_row_actions', $actions, $post, $this->detached ); return $actions; } }
01happy-blog
trunk/myblog/wp-admin/includes/class-wp-media-list-table.php
PHP
oos
13,580