Пример #1
0
/**
 * Register all HiveQueen scripts.
 *
 * Localizes some of them.
 * args order: $scripts->add( 'handle', 'url', 'dependencies', 'query-string', 1 );
 * when last arg === 1 queues the script for the footer
 *
 * @since 0.0.1
 *
 * @param HQ_Scripts $scripts HQ_Scripts object.
 */
function hq_default_scripts(&$scripts)
{
    //print("hq_default_scripts: Begin");
    include ABSPATH . HQINC . '/version.php';
    // include an unmodified $hq_version
    $develop_src = false !== strpos($hq_version, '-src');
    if (!defined('SCRIPT_DEBUG')) {
        define('SCRIPT_DEBUG', $develop_src);
    }
    if (!($guessurl = site_url())) {
        $guessed_url = true;
        $guessurl = hq_guess_url();
    }
    $scripts->base_url = $guessurl;
    $scripts->content_url = defined('HQ_CONTENT_URL') ? HQ_CONTENT_URL : '';
    $scripts->default_version = get_bloginfo('version');
    $scripts->default_dirs = array('/hq-admin/js/', '/hq-includes/js/');
    $suffix = SCRIPT_DEBUG ? '' : '.min';
    $dev_suffix = $develop_src ? '' : '.min';
    $scripts->add('utils', "/hq-includes/js/utils{$suffix}.js");
    did_action('init') && $scripts->localize('utils', 'userSettings', array('url' => (string) SITECOOKIEPATH, 'uid' => (string) get_current_user_id(), 'time' => (string) time(), 'secure' => (string) ('https' === parse_url(site_url(), PHP_URL_SCHEME))));
    $scripts->add('common', "/hq-admin/js/common{$suffix}.js", array('jquery', 'hoverIntent', 'utils'), false, 1);
    did_action('init') && $scripts->localize('common', 'commonL10n', array('warnDelete' => __("You are about to permanently delete the selected items.\n  'Cancel' to stop, 'OK' to delete."), 'dismiss' => __('Dismiss this notice.')));
    $scripts->add('hq-a11y', "/hq-includes/js/hq-a11y{$suffix}.js", array('jquery'), false, 1);
    $scripts->add('sack', "/hq-includes/js/tw-sack{$suffix}.js", array(), '1.6.1', 1);
    $scripts->add('quicktags', "/hq-includes/js/quicktags{$suffix}.js", array(), false, 1);
    did_action('init') && $scripts->localize('quicktags', 'quicktagsL10n', array('closeAllOpenTags' => __('Close all open tags'), 'closeTags' => __('close tags'), 'enterURL' => __('Enter the URL'), 'enterImageURL' => __('Enter the URL of the image'), 'enterImageDescription' => __('Enter a description of the image'), 'textdirection' => __('text direction'), 'toggleTextdirection' => __('Toggle Editor Text Direction'), 'dfw' => __('Distraction-free writing mode'), 'strong' => __('Bold'), 'strongClose' => __('Close bold tag'), 'em' => __('Italic'), 'emClose' => __('Close italic tag'), 'link' => __('Insert link'), 'blockquote' => __('Blockquote'), 'blockquoteClose' => __('Close blockquote tag'), 'del' => __('Deleted text (strikethrough)'), 'delClose' => __('Close deleted text tag'), 'ins' => __('Inserted text'), 'insClose' => __('Close inserted text tag'), 'image' => __('Insert image'), 'ul' => __('Bulleted list'), 'ulClose' => __('Close bulleted list tag'), 'ol' => __('Numbered list'), 'olClose' => __('Close numbered list tag'), 'li' => __('List item'), 'liClose' => __('Close list item tag'), 'code' => __('Code'), 'codeClose' => __('Close code tag'), 'more' => __('Insert Read More tag')));
    $scripts->add('colorpicker', "/hq-includes/js/colorpicker{$suffix}.js", array('prototype'), '3517m');
    $scripts->add('editor', "/hq-admin/js/editor{$suffix}.js", array('utils', 'jquery'), false, 1);
    // Back-compat for old DFW. To-do: remove at the end of 2016.
    $scripts->add('hq-fullscreen-stub', "/hq-admin/js/hq-fullscreen-stub{$suffix}.js", array(), false, 1);
    $scripts->add('hq-ajax-response', "/hq-includes/js/hq-ajax-response{$suffix}.js", array('jquery'), false, 1);
    did_action('init') && $scripts->localize('hq-ajax-response', 'hqAjax', array('noPerm' => __('You do not have permission to do that.'), 'broken' => __('An unidentified error has occurred.')));
    $scripts->add('hq-pointer', "/hq-includes/js/hq-pointer{$suffix}.js", array('jquery-ui-widget', 'jquery-ui-position'), '20111129a', 1);
    did_action('init') && $scripts->localize('hq-pointer', 'hqPointerL10n', array('dismiss' => __('Dismiss')));
    $scripts->add('autosave', "/hq-includes/js/autosave{$suffix}.js", array('heartbeat'), false, 1);
    $scripts->add('heartbeat', "/hq-includes/js/heartbeat{$suffix}.js", array('jquery'), false, 1);
    did_action('init') && $scripts->localize('heartbeat', 'heartbeatSettings', apply_filters('heartbeat_settings', array()));
    $scripts->add('hq-auth-check', "/hq-includes/js/hq-auth-check{$suffix}.js", array('heartbeat'), false, 1);
    did_action('init') && $scripts->localize('hq-auth-check', 'authcheckL10n', array('beforeunload' => __('Your session has expired. You can log in again from this page or go to the login page.'), 'interval' => apply_filters('hq_auth_check_interval', 3 * MINUTE_IN_SECONDS)));
    $scripts->add('hq-lists', "/hq-includes/js/hq-lists{$suffix}.js", array('hq-ajax-response', 'jquery-color'), false, 1);
    // HiveQueen no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source.
    $scripts->add('prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1');
    $scripts->add('scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array('prototype'), '1.9.0');
    $scripts->add('scriptaculous-builder', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array('scriptaculous-root'), '1.9.0');
    $scripts->add('scriptaculous-dragdrop', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.9.0');
    $scripts->add('scriptaculous-effects', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array('scriptaculous-root'), '1.9.0');
    $scripts->add('scriptaculous-slider', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array('scriptaculous-effects'), '1.9.0');
    $scripts->add('scriptaculous-sound', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array('scriptaculous-root'), '1.9.0');
    $scripts->add('scriptaculous-controls', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array('scriptaculous-root'), '1.9.0');
    $scripts->add('scriptaculous', false, array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'));
    // not used in core, replaced by Jcrop.js
    $scripts->add('cropper', '/hq-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'));
    // jQuery
    $scripts->add('jquery', false, array('jquery-core', 'jquery-migrate'), '1.11.3');
    $scripts->add('jquery-core', '/hq-includes/js/jquery/jquery.js', array(), '1.11.3');
    $scripts->add('jquery-migrate', "/hq-includes/js/jquery/jquery-migrate{$suffix}.js", array(), '1.2.1');
    // full jQuery UI
    $scripts->add('jquery-ui-core', "/hq-includes/js/jquery/ui/core{$dev_suffix}.js", array('jquery'), '1.11.4', 1);
    $scripts->add('jquery-effects-core', "/hq-includes/js/jquery/ui/effect{$dev_suffix}.js", array('jquery'), '1.11.4', 1);
    $scripts->add('jquery-effects-blind', "/hq-includes/js/jquery/ui/effect-blind{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-bounce', "/hq-includes/js/jquery/ui/effect-bounce{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-clip', "/hq-includes/js/jquery/ui/effect-clip{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-drop', "/hq-includes/js/jquery/ui/effect-drop{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-explode', "/hq-includes/js/jquery/ui/effect-explode{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-fade', "/hq-includes/js/jquery/ui/effect-fade{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-fold', "/hq-includes/js/jquery/ui/effect-fold{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-highlight', "/hq-includes/js/jquery/ui/effect-highlight{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-puff', "/hq-includes/js/jquery/ui/effect-puff{$dev_suffix}.js", array('jquery-effects-core', 'jquery-effects-scale'), '1.11.4', 1);
    $scripts->add('jquery-effects-pulsate', "/hq-includes/js/jquery/ui/effect-pulsate{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-scale', "/hq-includes/js/jquery/ui/effect-scale{$dev_suffix}.js", array('jquery-effects-core', 'jquery-effects-size'), '1.11.4', 1);
    $scripts->add('jquery-effects-shake', "/hq-includes/js/jquery/ui/effect-shake{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-size', "/hq-includes/js/jquery/ui/effect-size{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-slide', "/hq-includes/js/jquery/ui/effect-slide{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-effects-transfer', "/hq-includes/js/jquery/ui/effect-transfer{$dev_suffix}.js", array('jquery-effects-core'), '1.11.4', 1);
    $scripts->add('jquery-ui-accordion', "/hq-includes/js/jquery/ui/accordion{$dev_suffix}.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1);
    $scripts->add('jquery-ui-autocomplete', "/hq-includes/js/jquery/ui/autocomplete{$dev_suffix}.js", array('jquery-ui-menu'), '1.11.4', 1);
    $scripts->add('jquery-ui-button', "/hq-includes/js/jquery/ui/button{$dev_suffix}.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1);
    $scripts->add('jquery-ui-datepicker', "/hq-includes/js/jquery/ui/datepicker{$dev_suffix}.js", array('jquery-ui-core'), '1.11.4', 1);
    $scripts->add('jquery-ui-dialog', "/hq-includes/js/jquery/ui/dialog{$dev_suffix}.js", array('jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button', 'jquery-ui-position'), '1.11.4', 1);
    $scripts->add('jquery-ui-draggable', "/hq-includes/js/jquery/ui/draggable{$dev_suffix}.js", array('jquery-ui-mouse'), '1.11.4', 1);
    $scripts->add('jquery-ui-droppable', "/hq-includes/js/jquery/ui/droppable{$dev_suffix}.js", array('jquery-ui-draggable'), '1.11.4', 1);
    $scripts->add('jquery-ui-menu', "/hq-includes/js/jquery/ui/menu{$dev_suffix}.js", array('jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position'), '1.11.4', 1);
    $scripts->add('jquery-ui-mouse', "/hq-includes/js/jquery/ui/mouse{$dev_suffix}.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1);
    $scripts->add('jquery-ui-position', "/hq-includes/js/jquery/ui/position{$dev_suffix}.js", array('jquery'), '1.11.4', 1);
    $scripts->add('jquery-ui-progressbar', "/hq-includes/js/jquery/ui/progressbar{$dev_suffix}.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1);
    $scripts->add('jquery-ui-resizable', "/hq-includes/js/jquery/ui/resizable{$dev_suffix}.js", array('jquery-ui-mouse'), '1.11.4', 1);
    $scripts->add('jquery-ui-selectable', "/hq-includes/js/jquery/ui/selectable{$dev_suffix}.js", array('jquery-ui-mouse'), '1.11.4', 1);
    $scripts->add('jquery-ui-selectmenu', "/hq-includes/js/jquery/ui/selectmenu{$dev_suffix}.js", array('jquery-ui-menu'), '1.11.4', 1);
    $scripts->add('jquery-ui-slider', "/hq-includes/js/jquery/ui/slider{$dev_suffix}.js", array('jquery-ui-mouse'), '1.11.4', 1);
    $scripts->add('jquery-ui-sortable', "/hq-includes/js/jquery/ui/sortable{$dev_suffix}.js", array('jquery-ui-mouse'), '1.11.4', 1);
    $scripts->add('jquery-ui-spinner', "/hq-includes/js/jquery/ui/spinner{$dev_suffix}.js", array('jquery-ui-button'), '1.11.4', 1);
    $scripts->add('jquery-ui-tabs', "/hq-includes/js/jquery/ui/tabs{$dev_suffix}.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1);
    $scripts->add('jquery-ui-tooltip', "/hq-includes/js/jquery/ui/tooltip{$dev_suffix}.js", array('jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position'), '1.11.4', 1);
    $scripts->add('jquery-ui-widget', "/hq-includes/js/jquery/ui/widget{$dev_suffix}.js", array('jquery'), '1.11.4', 1);
    // deprecated, not used in core, most functionality is included in jQuery 1.3
    $scripts->add('jquery-form', "/hq-includes/js/jquery/jquery.form{$suffix}.js", array('jquery'), '3.37.0', 1);
    // jQuery plugins
    $scripts->add('jquery-color', "/hq-includes/js/jquery/jquery.color.min.js", array('jquery'), '2.1.1', 1);
    $scripts->add('suggest', "/hq-includes/js/jquery/suggest{$suffix}.js", array('jquery'), '1.1-20110113', 1);
    $scripts->add('schedule', '/hq-includes/js/jquery/jquery.schedule.js', array('jquery'), '20m', 1);
    $scripts->add('jquery-query', "/hq-includes/js/jquery/jquery.query.js", array('jquery'), '2.1.7', 1);
    $scripts->add('jquery-serialize-object', "/hq-includes/js/jquery/jquery.serialize-object.js", array('jquery'), '0.2', 1);
    $scripts->add('jquery-hotkeys', "/hq-includes/js/jquery/jquery.hotkeys{$suffix}.js", array('jquery'), '0.0.2m', 1);
    $scripts->add('jquery-table-hotkeys', "/hq-includes/js/jquery/jquery.table-hotkeys{$suffix}.js", array('jquery', 'jquery-hotkeys'), false, 1);
    $scripts->add('jquery-touch-punch', "/hq-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1);
    // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
    // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
    $scripts->add('masonry', "/hq-includes/js/masonry.min.js", array(), '3.1.2', 1);
    $scripts->add('jquery-masonry', "/hq-includes/js/jquery/jquery.masonry{$dev_suffix}.js", array('jquery', 'masonry'), '3.1.2', 1);
    $scripts->add('thickbox', "/hq-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20121105', 1);
    did_action('init') && $scripts->localize('thickbox', 'thickboxL10n', array('next' => __('Next >'), 'prev' => __('< Prev'), 'image' => __('Image'), 'of' => __('of'), 'close' => __('Close'), 'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'), 'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif')));
    $scripts->add('jcrop', "/hq-includes/js/jcrop/jquery.Jcrop.min.js", array('jquery'), '0.9.12');
    $scripts->add('swfobject', "/hq-includes/js/swfobject.js", array(), '2.2-20120417');
    // error message for both plupload and swfupload
    $uploader_l10n = array('queue_limit_exceeded' => __('You have attempted to queue too many files.'), 'file_exceeds_size_limit' => __('%s exceeds the maximum upload size for this site.'), 'zero_byte_file' => __('This file is empty. Please try another.'), 'invalid_filetype' => __('This file type is not allowed. Please try another.'), 'not_an_image' => __('This file is not an image. Please try another.'), 'image_memory_exceeded' => __('Memory exceeded. Please try another smaller file.'), 'image_dimensions_exceeded' => __('This is larger than the maximum size. Please try another.'), 'default_error' => __('An error occurred in the upload. Please try again later.'), 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), 'upload_limit_exceeded' => __('You may only upload 1 file.'), 'http_error' => __('HTTP error.'), 'upload_failed' => __('Upload failed.'), 'big_upload_failed' => __('Please try uploading this file with the %1$sbrowser uploader%2$s.'), 'big_upload_queued' => __('%s exceeds the maximum upload size for the multi-file uploader when used in your browser.'), 'io_error' => __('IO error.'), 'security_error' => __('Security error.'), 'file_cancelled' => __('File canceled.'), 'upload_stopped' => __('Upload stopped.'), 'dismiss' => __('Dismiss'), 'crunching' => __('Crunching…'), 'deleted' => __('moved to the trash.'), 'error_uploading' => __('“%s” has failed to upload.'));
    $scripts->add('plupload', '/hq-includes/js/plupload/plupload.full.min.js', array(), '2.1.1');
    // Back compat handles:
    foreach (array('all', 'html5', 'flash', 'silverlight', 'html4') as $handle) {
        $scripts->add("plupload-{$handle}", false, array('plupload'), '2.1.1');
    }
    $scripts->add('plupload-handlers', "/hq-includes/js/plupload/handlers{$suffix}.js", array('plupload', 'jquery'));
    did_action('init') && $scripts->localize('plupload-handlers', 'pluploadL10n', $uploader_l10n);
    $scripts->add('hq-plupload', "/hq-includes/js/plupload/hq-plupload{$suffix}.js", array('plupload', 'jquery', 'json2', 'media-models'), false, 1);
    did_action('init') && $scripts->localize('hq-plupload', 'pluploadL10n', $uploader_l10n);
    // keep 'swfupload' for back-compat.
    $scripts->add('swfupload', '/hq-includes/js/swfupload/swfupload.js', array(), '2201-20110113');
    $scripts->add('swfupload-swfobject', '/hq-includes/js/swfupload/plugins/swfupload.swfobject.js', array('swfupload', 'swfobject'), '2201a');
    $scripts->add('swfupload-queue', '/hq-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2201');
    $scripts->add('swfupload-speed', '/hq-includes/js/swfupload/plugins/swfupload.speed.js', array('swfupload'), '2201');
    $scripts->add('swfupload-all', false, array('swfupload', 'swfupload-swfobject', 'swfupload-queue'), '2201');
    $scripts->add('swfupload-handlers', "/hq-includes/js/swfupload/handlers{$suffix}.js", array('swfupload-all', 'jquery'), '2201-20110524');
    did_action('init') && $scripts->localize('swfupload-handlers', 'swfuploadL10n', $uploader_l10n);
    $scripts->add('comment-reply', "/hq-includes/js/comment-reply{$suffix}.js", array(), false, 1);
    $scripts->add('json2', "/hq-includes/js/json2{$suffix}.js", array(), '2011-02-23');
    did_action('init') && $scripts->add_data('json2', 'conditional', 'lt IE 8');
    $scripts->add('underscore', "/hq-includes/js/underscore{$dev_suffix}.js", array(), '1.6.0', 1);
    $scripts->add('backbone', "/hq-includes/js/backbone{$dev_suffix}.js", array('underscore', 'jquery'), '1.1.2', 1);
    $scripts->add('hq-util', "/hq-includes/js/hq-util{$suffix}.js", array('underscore', 'jquery'), false, 1);
    did_action('init') && $scripts->localize('hq-util', '_hqUtilSettings', array('ajax' => array('url' => admin_url('admin-ajax.php', 'relative'))));
    $scripts->add('hq-backbone', "/hq-includes/js/hq-backbone{$suffix}.js", array('backbone', 'hq-util'), false, 1);
    $scripts->add('revisions', "/hq-admin/js/revisions{$suffix}.js", array('hq-backbone', 'jquery-ui-slider', 'hoverIntent'), false, 1);
    $scripts->add('imgareaselect', "/hq-includes/js/imgareaselect/jquery.imgareaselect{$suffix}.js", array('jquery'), false, 1);
    $scripts->add('mediaelement', "/hq-includes/js/mediaelement/mediaelement-and-player.min.js", array('jquery'), '2.17.0', 1);
    did_action('init') && $scripts->localize('mediaelement', 'mejsL10n', array('language' => get_bloginfo('language'), 'strings' => array('Close' => __('Close'), 'Fullscreen' => __('Fullscreen'), 'Download File' => __('Download File'), 'Download Video' => __('Download Video'), 'Play/Pause' => __('Play/Pause'), 'Mute Toggle' => __('Mute Toggle'), 'None' => __('None'), 'Turn off Fullscreen' => __('Turn off Fullscreen'), 'Go Fullscreen' => __('Go Fullscreen'), 'Unmute' => __('Unmute'), 'Mute' => __('Mute'), 'Captions/Subtitles' => __('Captions/Subtitles'))));
    $scripts->add('hq-mediaelement', "/hq-includes/js/mediaelement/hq-mediaelement.js", array('mediaelement'), false, 1);
    did_action('init') && $scripts->localize('mediaelement', '_hqmejsSettings', array('pluginPath' => includes_url('js/mediaelement/', 'relative')));
    $scripts->add('froogaloop', "/hq-includes/js/mediaelement/froogaloop.min.js", array(), '2.0');
    $scripts->add('hq-playlist', "/hq-includes/js/mediaelement/hq-playlist.js", array('hq-util', 'backbone', 'mediaelement'), false, 1);
    $scripts->add('zxcvbn-async', "/hq-includes/js/zxcvbn-async{$suffix}.js", array(), '1.0');
    did_action('init') && $scripts->localize('zxcvbn-async', '_zxcvbnSettings', array('src' => empty($guessed_url) ? includes_url('/js/zxcvbn.min.js') : $scripts->base_url . '/hq-includes/js/zxcvbn.min.js'));
    $scripts->add('password-strength-meter', "/hq-admin/js/password-strength-meter{$suffix}.js", array('jquery', 'zxcvbn-async'), false, 1);
    did_action('init') && $scripts->localize('password-strength-meter', 'pwsL10n', array('short' => _x('Very weak', 'password strength'), 'bad' => _x('Weak', 'password strength'), 'good' => _x('Medium', 'password strength'), 'strong' => _x('Strong', 'password strength'), 'mismatch' => _x('Mismatch', 'password mismatch')));
    $scripts->add('user-profile', "/hq-admin/js/user-profile{$suffix}.js", array('jquery', 'password-strength-meter', 'hq-util'), false, 1);
    did_action('init') && $scripts->localize('user-profile', 'userProfileL10n', array('warn' => __('Your new password has not been saved.'), 'show' => __('Show'), 'hide' => __('Hide'), 'cancel' => __('Cancel'), 'ariaShow' => esc_attr__('Show password'), 'ariaHide' => esc_attr__('Hide password')));
    $scripts->add('language-chooser', "/hq-admin/js/language-chooser{$suffix}.js", array('jquery'), false, 1);
    $scripts->add('user-suggest', "/hq-admin/js/user-suggest{$suffix}.js", array('jquery-ui-autocomplete'), false, 1);
    $scripts->add('admin-bar', "/hq-includes/js/admin-bar{$suffix}.js", array(), false, 1);
    $scripts->add('hqlink', "/hq-includes/js/hqlink{$suffix}.js", array('jquery'), false, 1);
    did_action('init') && $scripts->localize('hqlink', 'hqLinkL10n', array('title' => __('Insert/edit link'), 'update' => __('Update'), 'save' => __('Add Link'), 'noTitle' => __('(no title)'), 'noMatchesFound' => __('No results found.')));
    $scripts->add('hqdialogs', "/hq-includes/js/hqdialog{$suffix}.js", array('jquery-ui-dialog'), false, 1);
    $scripts->add('word-count', "/hq-admin/js/word-count{$suffix}.js", array(), false, 1);
    did_action('init') && $scripts->localize('word-count', 'wordCountL10n', array('type' => _x('words', 'Word count type. Do not translate!'), 'shortcodes' => !empty($GLOBALS['shortcode_tags']) ? array_keys($GLOBALS['shortcode_tags']) : array()));
    $scripts->add('media-upload', "/hq-admin/js/media-upload{$suffix}.js", array('thickbox', 'shortcode'), false, 1);
    $scripts->add('hoverIntent', "/hq-includes/js/hoverIntent{$suffix}.js", array('jquery'), '1.8.1', 1);
    $scripts->add('customize-base', "/hq-includes/js/customize-base{$suffix}.js", array('jquery', 'json2', 'underscore'), false, 1);
    $scripts->add('customize-loader', "/hq-includes/js/customize-loader{$suffix}.js", array('customize-base'), false, 1);
    $scripts->add('customize-preview', "/hq-includes/js/customize-preview{$suffix}.js", array('customize-base'), false, 1);
    $scripts->add('customize-models', "/hq-includes/js/customize-models.js", array('underscore', 'backbone'), false, 1);
    $scripts->add('customize-views', "/hq-includes/js/customize-views.js", array('jquery', 'underscore', 'imgareaselect', 'customize-models', 'media-editor', 'media-views'), false, 1);
    $scripts->add('customize-controls', "/hq-admin/js/customize-controls{$suffix}.js", array('customize-base', 'hq-a11y'), false, 1);
    did_action('init') && $scripts->localize('customize-controls', '_hqCustomizeControlsL10n', array('activate' => __('Save & Activate'), 'save' => __('Save & Publish'), 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), 'saved' => __('Saved'), 'cancel' => __('Cancel'), 'close' => __('Close'), 'cheatin' => __('Cheatin’ uh?'), 'previewIframeTitle' => __('Site Preview'), 'loginIframeTitle' => __('Session expired'), 'collapseSidebar' => __('Collapse Sidebar'), 'expandSidebar' => __('Expand Sidebar'), 'allowedFiles' => __('Allowed Files')));
    $scripts->add('customize-widgets', "/hq-admin/js/customize-widgets{$suffix}.js", array('jquery', 'jquery-ui-sortable', 'jquery-ui-droppable', 'hq-backbone', 'customize-controls'), false, 1);
    $scripts->add('customize-preview-widgets', "/hq-includes/js/customize-preview-widgets{$suffix}.js", array('jquery', 'hq-util', 'customize-preview'), false, 1);
    $scripts->add('customize-nav-menus', "/hq-admin/js/customize-nav-menus{$suffix}.js", array('jquery', 'hq-backbone', 'customize-controls', 'accordion', 'nav-menu'), false, 1);
    $scripts->add('customize-preview-nav-menus', "/hq-includes/js/customize-preview-nav-menus{$suffix}.js", array('jquery', 'hq-util', 'customize-preview'), false, 1);
    $scripts->add('accordion', "/hq-admin/js/accordion{$suffix}.js", array('jquery'), false, 1);
    $scripts->add('shortcode', "/hq-includes/js/shortcode{$suffix}.js", array('underscore'), false, 1);
    $scripts->add('media-models', "/hq-includes/js/media-models{$suffix}.js", array('hq-backbone'), false, 1);
    did_action('init') && $scripts->localize('media-models', '_hqMediaModelsL10n', array('settings' => array('ajaxurl' => admin_url('admin-ajax.php', 'relative'), 'post' => array('id' => 0))));
    // To enqueue media-views or media-editor, call hq_enqueue_media().
    // Both rely on numerous settings, styles, and templates to operate correctly.
    $scripts->add('media-views', "/hq-includes/js/media-views{$suffix}.js", array('utils', 'media-models', 'hq-plupload', 'jquery-ui-sortable', 'hq-mediaelement'), false, 1);
    $scripts->add('media-editor', "/hq-includes/js/media-editor{$suffix}.js", array('shortcode', 'media-views'), false, 1);
    $scripts->add('media-audiovideo', "/hq-includes/js/media-audiovideo{$suffix}.js", array('media-editor'), false, 1);
    $scripts->add('mce-view', "/hq-includes/js/mce-view{$suffix}.js", array('shortcode', 'jquery', 'media-views', 'media-audiovideo'), false, 1);
    if (is_admin()) {
        $scripts->add('admin-tags', "/hq-admin/js/tags{$suffix}.js", array('jquery', 'hq-ajax-response'), false, 1);
        did_action('init') && $scripts->localize('admin-tags', 'tagsl10n', array('noPerm' => __('You do not have permission to do that.'), 'broken' => __('An unidentified error has occurred.')));
        $scripts->add('admin-comments', "/hq-admin/js/edit-comments{$suffix}.js", array('hq-lists', 'quicktags', 'jquery-query'), false, 1);
        did_action('init') && $scripts->localize('admin-comments', 'adminCommentsL10n', array('hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']), 'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']), 'replyApprove' => __('Approve and Reply'), 'reply' => __('Reply'), 'warnQuickEdit' => __("Are you sure you want to edit this comment?\nThe changes you made will be lost.")));
        $scripts->add('xfn', "/hq-admin/js/xfn{$suffix}.js", array('jquery'), false, 1);
        $scripts->add('postbox', "/hq-admin/js/postbox{$suffix}.js", array('jquery-ui-sortable'), false, 1);
        $scripts->add('tags-box', "/hq-admin/js/tags-box{$suffix}.js", array('jquery', 'suggest'), false, 1);
        did_action('init') && $scripts->localize('tags-box', 'tagsBoxL10n', array('tagDelimiter' => _x(',', 'tag delimiter')));
        $scripts->add('post', "/hq-admin/js/post{$suffix}.js", array('suggest', 'hq-lists', 'postbox', 'tags-box', 'underscore', 'word-count'), false, 1);
        did_action('init') && $scripts->localize('post', 'postL10n', array('ok' => __('OK'), 'cancel' => __('Cancel'), 'publishOn' => __('Publish on:'), 'publishOnFuture' => __('Schedule for:'), 'publishOnPast' => __('Published on:'), 'dateFormat' => __('%1$s %2$s, %3$s @ %4$s:%5$s'), 'showcomm' => __('Show more comments'), 'endcomm' => __('No more comments found.'), 'publish' => __('Publish'), 'schedule' => __('Schedule'), 'update' => __('Update'), 'savePending' => __('Save as Pending'), 'saveDraft' => __('Save Draft'), 'private' => __('Private'), 'public' => __('Public'), 'publicSticky' => __('Public, Sticky'), 'password' => __('Password Protected'), 'privatelyPublished' => __('Privately Published'), 'published' => __('Published'), 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), 'savingText' => __('Saving Draft…')));
        $scripts->add('press-this', "/hq-admin/js/press-this{$suffix}.js", array('jquery', 'tags-box'), false, 1);
        did_action('init') && $scripts->localize('press-this', 'pressThisL10n', array('newPost' => __('Title'), 'serverError' => __('Connection lost or the server is busy. Please try again later.'), 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), 'suggestedEmbedAlt' => __('Suggested embed #%d'), 'suggestedImgAlt' => __('Suggested image #%d')));
        $scripts->add('editor-expand', "/hq-admin/js/editor-expand{$suffix}.js", array('jquery'), false, 1);
        $scripts->add('link', "/hq-admin/js/link{$suffix}.js", array('hq-lists', 'postbox'), false, 1);
        $scripts->add('comment', "/hq-admin/js/comment{$suffix}.js", array('jquery', 'postbox'));
        $scripts->add_data('comment', 'group', 1);
        did_action('init') && $scripts->localize('comment', 'commentL10n', array('submittedOn' => __('Submitted on:'), 'dateFormat' => __('%1$s %2$s, %3$s @ %4$s:%5$s')));
        $scripts->add('admin-gallery', "/hq-admin/js/gallery{$suffix}.js", array('jquery-ui-sortable'));
        $scripts->add('admin-widgets', "/hq-admin/js/widgets{$suffix}.js", array('jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable'), false, 1);
        $scripts->add('theme', "/hq-admin/js/theme{$suffix}.js", array('hq-backbone', 'hq-a11y'), false, 1);
        $scripts->add('inline-edit-post', "/hq-admin/js/inline-edit-post{$suffix}.js", array('jquery', 'suggest'), false, 1);
        did_action('init') && $scripts->localize('inline-edit-post', 'inlineEditL10n', array('error' => __('Error while saving the changes.'), 'ntdeltitle' => __('Remove From Bulk Edit'), 'notitle' => __('(no title)'), 'comma' => trim(_x(',', 'tag delimiter'))));
        $scripts->add('inline-edit-tax', "/hq-admin/js/inline-edit-tax{$suffix}.js", array('jquery'), false, 1);
        did_action('init') && $scripts->localize('inline-edit-tax', 'inlineEditL10n', array('error' => __('Error while saving the changes.')));
        $scripts->add('plugin-install', "/hq-admin/js/plugin-install{$suffix}.js", array('jquery', 'thickbox'), false, 1);
        did_action('init') && $scripts->localize('plugin-install', 'plugininstallL10n', array('plugin_information' => __('Plugin Information:'), 'ays' => __('Are you sure you want to install this plugin?')));
        $scripts->add('updates', "/hq-admin/js/updates{$suffix}.js", array('jquery', 'hq-util', 'hq-a11y'));
        did_action('init') && $scripts->localize('updates', '_hqUpdatesSettings', array('ajax_nonce' => hq_create_nonce('updates'), 'l10n' => array('updating' => __('Updating...'), 'updated' => __('Updated!'), 'updateFailed' => __('Update Failed: %s'), 'updatingLabel' => __('Updating %s...'), 'updatedLabel' => __('%s updated!'), 'updateFailedLabel' => __('%s update failed'), 'updatingMsg' => __('Updating... please wait.'), 'updatedMsg' => __('Update completed successfully.'), 'updateCancel' => __('Update canceled.'), 'beforeunload' => __('Plugin updates may not complete if you navigate away from this page.'))));
        $scripts->add('farbtastic', '/hq-admin/js/farbtastic.js', array('jquery'), '1.2');
        $scripts->add('iris', '/hq-admin/js/iris.min.js', array('jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch'), '1.0.7', 1);
        $scripts->add('hq-color-picker', "/hq-admin/js/color-picker{$suffix}.js", array('iris'), false, 1);
        did_action('init') && $scripts->localize('hq-color-picker', 'hqColorPickerL10n', array('clear' => __('Clear'), 'defaultString' => __('Default'), 'pick' => __('Select Color'), 'current' => __('Current Color')));
        $scripts->add('dashboard', "/hq-admin/js/dashboard{$suffix}.js", array('jquery', 'admin-comments', 'postbox'), false, 1);
        $scripts->add('list-revisions', "/hq-includes/js/hq-list-revisions{$suffix}.js");
        $scripts->add('media-grid', "/hq-includes/js/media-grid{$suffix}.js", array('media-editor'), false, 1);
        $scripts->add('media', "/hq-admin/js/media{$suffix}.js", array('jquery'), false, 1);
        did_action('init') && $scripts->localize('media', 'attachMediaBoxL10n', array('error' => __('An error has occurred. Please reload the page and try again.')));
        $scripts->add('image-edit', "/hq-admin/js/image-edit{$suffix}.js", array('jquery', 'json2', 'imgareaselect'), false, 1);
        did_action('init') && $scripts->localize('image-edit', 'imageEditL10n', array('error' => __('Could not load the preview image. Please reload the page and try again.')));
        $scripts->add('set-post-thumbnail', "/hq-admin/js/set-post-thumbnail{$suffix}.js", array('jquery'), false, 1);
        did_action('init') && $scripts->localize('set-post-thumbnail', 'setPostThumbnailL10n', array('setThumbnail' => __('Use as featured image'), 'saving' => __('Saving...'), 'error' => __('Could not set that as the thumbnail image. Try a different attachment.'), 'done' => __('Done')));
        // Navigation Menus
        $scripts->add('nav-menu', "/hq-admin/js/nav-menu{$suffix}.js", array('jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'hq-lists', 'postbox'));
        did_action('init') && $scripts->localize('nav-menu', 'navMenuL10n', array('noResultsFound' => __('No results found.'), 'warnDeleteMenu' => __("You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete."), 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), 'untitled' => _x('(no label)', 'missing menu item navigation label')));
        $scripts->add('custom-header', "/hq-admin/js/custom-header.js", array('jquery-masonry'), false, 1);
        $scripts->add('custom-background', "/hq-admin/js/custom-background{$suffix}.js", array('hq-color-picker', 'media-views'), false, 1);
        $scripts->add('media-gallery', "/hq-admin/js/media-gallery{$suffix}.js", array('jquery'), false, 1);
        $scripts->add('svg-painter', '/hq-admin/js/svg-painter.js', array('jquery'), false, 1);
    }
}
Пример #2
0
/**
 * {@internal Missing Short Description}}
 *
 * @since 0.0.1
 *
 * @staticvar string $update_nonce
 *
 * @param array $entry
 * @param int   $count
 * @return string
 */
function _list_meta_row($entry, &$count)
{
    static $update_nonce = '';
    if (is_protected_meta($entry['meta_key'], 'post')) {
        return '';
    }
    if (!$update_nonce) {
        $update_nonce = hq_create_nonce('add-meta');
    }
    $r = '';
    ++$count;
    if (is_serialized($entry['meta_value'])) {
        if (is_serialized_string($entry['meta_value'])) {
            // This is a serialized string, so we should display it.
            $entry['meta_value'] = maybe_unserialize($entry['meta_value']);
        } else {
            // This is a serialized array/object so we should NOT display it.
            --$count;
            return '';
        }
    }
    $entry['meta_key'] = esc_attr($entry['meta_key']);
    $entry['meta_value'] = esc_textarea($entry['meta_value']);
    // using a <textarea />
    $entry['meta_id'] = (int) $entry['meta_id'];
    $delete_nonce = hq_create_nonce('delete-meta_' . $entry['meta_id']);
    $r .= "\n\t<tr id='meta-{$entry['meta_id']}'>";
    $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta-{$entry['meta_id']}-key'>" . __('Key') . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta-{$entry['meta_id']}-key' type='text' size='20' value='{$entry['meta_key']}' />";
    $r .= "\n\t\t<div class='submit'>";
    $r .= get_submit_button(__('Delete'), 'deletemeta small', "deletemeta[{$entry['meta_id']}]", false, array('data-hq-lists' => "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce={$delete_nonce}"));
    $r .= "\n\t\t";
    $r .= get_submit_button(__('Update'), 'updatemeta small', "meta-{$entry['meta_id']}-submit", false, array('data-hq-lists' => "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta={$update_nonce}"));
    $r .= "</div>";
    $r .= hq_nonce_field('change-meta', '_ajax_nonce', false, false);
    $r .= "</td>";
    $r .= "\n\t\t<td><label class='screen-reader-text' for='meta-{$entry['meta_id']}-value'>" . __('Value') . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta-{$entry['meta_id']}-value' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";
    return $r;
}
Пример #3
0
/**
 * Retrieve or display nonce hidden field for forms.
 *
 * The nonce field is used to validate that the contents of the form came from
 * the location on the current site and not somewhere else. The nonce does not
 * offer absolute protection, but should protect against most cases. It is very
 * important to use nonce field in forms.
 *
 * The $action and $name are optional, but if you want to have better security,
 * it is strongly suggested to set those two parameters. It is easier to just
 * call the function without any parameters, because validation of the nonce
 * doesn't require any parameters, but since crackers know what the default is
 * it won't be difficult for them to find a way around your nonce and cause
 * damage.
 *
 * The input name will be whatever $name value you gave. The input value will be
 * the nonce creation value.
 *
 * @since 0.0.1
 *
 * @param int|string $action  Optional. Action name. Default -1.
 * @param string     $name    Optional. Nonce name. Default '_hqnonce'.
 * @param bool       $referer Optional. Whether to set the referer field for validation. Default true.
 * @param bool       $echo    Optional. Whether to display or return hidden form field. Default true.
 * @return string Nonce field HTML markup.
 */
function hq_nonce_field($action = -1, $name = "_hqnonce", $referer = true, $echo = true)
{
    $name = esc_attr($name);
    $nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . hq_create_nonce($action) . '" />';
    if ($referer) {
        $nonce_field .= hq_referer_field(false);
    }
    if ($echo) {
        echo $nonce_field;
    }
    return $nonce_field;
}
Пример #4
0
/**
 * Default settings for heartbeat
 *
 * Outputs the nonce used in the heartbeat XHR
 *
 * @since 0.0.1
 *
 * @param array $settings
 * @return array $settings
 */
function hq_heartbeat_settings($settings)
{
    if (!is_admin()) {
        $settings['ajaxurl'] = admin_url('admin-ajax.php', 'relative');
    }
    if (is_user_logged_in()) {
        $settings['nonce'] = hq_create_nonce('heartbeat-nonce');
    }
    return $settings;
}
Пример #5
0
/**
 * Enqueues all scripts, styles, settings, and templates necessary to use
 * all media JS APIs.
 *
 * @since 0.0.1
 *
 * @global int       $content_width
 * @global hqdb      $hqdb
 * @global HQ_Locale $hq_locale
 *
 * @param array $args {
 *     Arguments for enqueuing media scripts.
 *
 *     @type int|HQ_Post A post object or ID.
 * }
 */
function hq_enqueue_media($args = array())
{
    // Enqueue me just once per page, please.
    if (did_action('hq_enqueue_media')) {
        return;
    }
    global $content_width, $hqdb, $hq_locale;
    $defaults = array('post' => null);
    $args = hq_parse_args($args, $defaults);
    // We're going to pass the old thickbox media tabs to `media_upload_tabs`
    // to ensure plugins will work. We will then unset those tabs.
    $tabs = array('type' => '', 'type_url' => '', 'gallery' => '', 'library' => '');
    /** This filter is documented in hq-admin/includes/media.php */
    $tabs = apply_filters('media_upload_tabs', $tabs);
    unset($tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library']);
    $props = array('link' => get_option('image_default_link_type'), 'align' => get_option('image_default_align'), 'size' => get_option('image_default_size'));
    $exts = array_merge(hq_get_audio_extensions(), hq_get_video_extensions());
    $mimes = get_allowed_mime_types();
    $ext_mimes = array();
    foreach ($exts as $ext) {
        foreach ($mimes as $ext_preg => $mime_match) {
            if (preg_match('#' . $ext . '#i', $ext_preg)) {
                $ext_mimes[$ext] = $mime_match;
                break;
            }
        }
    }
    $has_audio = $hqdb->get_var("\n\t\tSELECT ID\n\t\tFROM {$hqdb->posts}\n\t\tWHERE post_type = 'attachment'\n\t\tAND post_mime_type LIKE 'audio%'\n\t\tLIMIT 1\n\t");
    $has_video = $hqdb->get_var("\n\t\tSELECT ID\n\t\tFROM {$hqdb->posts}\n\t\tWHERE post_type = 'attachment'\n\t\tAND post_mime_type LIKE 'video%'\n\t\tLIMIT 1\n\t");
    $months = $hqdb->get_results($hqdb->prepare("\n\t\tSELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month\n\t\tFROM {$hqdb->posts}\n\t\tWHERE post_type = %s\n\t\tORDER BY post_date DESC\n\t", 'attachment'));
    foreach ($months as $month_year) {
        $month_year->text = sprintf(__('%1$s %2$d'), $hq_locale->get_month($month_year->month), $month_year->year);
    }
    $settings = array('tabs' => $tabs, 'tabUrl' => add_query_arg(array('chromeless' => true), admin_url('media-upload.php')), 'mimeTypes' => hq_list_pluck(get_post_mime_types(), 0), 'captions' => !apply_filters('disable_captions', ''), 'nonce' => array('sendToEditor' => hq_create_nonce('media-send-to-editor')), 'post' => array('id' => 0), 'defaultProps' => $props, 'attachmentCounts' => array('audio' => $has_audio ? 1 : 0, 'video' => $has_video ? 1 : 0), 'embedExts' => $exts, 'embedMimes' => $ext_mimes, 'contentWidth' => $content_width, 'months' => $months, 'mediaTrash' => MEDIA_TRASH ? 1 : 0);
    $post = null;
    if (isset($args['post'])) {
        $post = get_post($args['post']);
        $settings['post'] = array('id' => $post->ID, 'nonce' => hq_create_nonce('update-post_' . $post->ID));
        $thumbnail_support = current_theme_supports('post-thumbnails', $post->post_type) && post_type_supports($post->post_type, 'thumbnail');
        if (!$thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type) {
            if (hq_attachment_is('audio', $post)) {
                $thumbnail_support = post_type_supports('attachment:audio', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:audio');
            } elseif (hq_attachment_is('video', $post)) {
                $thumbnail_support = post_type_supports('attachment:video', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:video');
            }
        }
        if ($thumbnail_support) {
            $featured_image_id = get_post_meta($post->ID, '_thumbnail_id', true);
            $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
        }
    }
    $hier = $post && is_post_type_hierarchical($post->post_type);
    if ($post) {
        $post_type_object = get_post_type_object($post->post_type);
    } else {
        $post_type_object = get_post_type_object('post');
    }
    $strings = array('url' => __('URL'), 'addMedia' => __('Add Media'), 'search' => __('Search'), 'select' => __('Select'), 'cancel' => __('Cancel'), 'update' => __('Update'), 'replace' => __('Replace'), 'remove' => __('Remove'), 'back' => __('Back'), 'selected' => __('%d selected'), 'dragInfo' => __('Drag and drop to reorder media files.'), 'uploadFilesTitle' => __('Upload Files'), 'uploadImagesTitle' => __('Upload Images'), 'mediaLibraryTitle' => __('Media Library'), 'insertMediaTitle' => __('Insert Media'), 'createNewGallery' => __('Create a new gallery'), 'createNewPlaylist' => __('Create a new playlist'), 'createNewVideoPlaylist' => __('Create a new video playlist'), 'returnToLibrary' => __('&#8592; Return to library'), 'allMediaItems' => __('All media items'), 'allDates' => __('All dates'), 'noItemsFound' => __('No items found.'), 'insertIntoPost' => $hier ? __('Insert into page') : __('Insert into post'), 'unattached' => __('Unattached'), 'trash' => _x('Trash', 'noun'), 'uploadedToThisPost' => $hier ? __('Uploaded to this page') : __('Uploaded to this post'), 'warnDelete' => __("You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete."), 'warnBulkDelete' => __("You are about to permanently delete these items.\n  'Cancel' to stop, 'OK' to delete."), 'warnBulkTrash' => __("You are about to trash these items.\n  'Cancel' to stop, 'OK' to delete."), 'bulkSelect' => __('Bulk Select'), 'cancelSelection' => __('Cancel Selection'), 'trashSelected' => __('Trash Selected'), 'untrashSelected' => __('Untrash Selected'), 'deleteSelected' => __('Delete Selected'), 'deletePermanently' => __('Delete Permanently'), 'apply' => __('Apply'), 'filterByDate' => __('Filter by date'), 'filterByType' => __('Filter by type'), 'searchMediaLabel' => __('Search Media'), 'noMedia' => __('No media attachments found.'), 'attachmentDetails' => __('Attachment Details'), 'insertFromUrlTitle' => __('Insert from URL'), 'setFeaturedImageTitle' => $post_type_object->labels->featured_image, 'setFeaturedImage' => $post_type_object->labels->set_featured_image, 'createGalleryTitle' => __('Create Gallery'), 'editGalleryTitle' => __('Edit Gallery'), 'cancelGalleryTitle' => __('&#8592; Cancel Gallery'), 'insertGallery' => __('Insert gallery'), 'updateGallery' => __('Update gallery'), 'addToGallery' => __('Add to gallery'), 'addToGalleryTitle' => __('Add to Gallery'), 'reverseOrder' => __('Reverse order'), 'imageDetailsTitle' => __('Image Details'), 'imageReplaceTitle' => __('Replace Image'), 'imageDetailsCancel' => __('Cancel Edit'), 'editImage' => __('Edit Image'), 'chooseImage' => __('Choose Image'), 'selectAndCrop' => __('Select and Crop'), 'skipCropping' => __('Skip Cropping'), 'cropImage' => __('Crop Image'), 'cropYourImage' => __('Crop your image'), 'cropping' => __('Cropping&hellip;'), 'suggestedDimensions' => __('Suggested image dimensions:'), 'cropError' => __('There has been an error cropping your image.'), 'audioDetailsTitle' => __('Audio Details'), 'audioReplaceTitle' => __('Replace Audio'), 'audioAddSourceTitle' => __('Add Audio Source'), 'audioDetailsCancel' => __('Cancel Edit'), 'videoDetailsTitle' => __('Video Details'), 'videoReplaceTitle' => __('Replace Video'), 'videoAddSourceTitle' => __('Add Video Source'), 'videoDetailsCancel' => __('Cancel Edit'), 'videoSelectPosterImageTitle' => __('Select Poster Image'), 'videoAddTrackTitle' => __('Add Subtitles'), 'playlistDragInfo' => __('Drag and drop to reorder tracks.'), 'createPlaylistTitle' => __('Create Audio Playlist'), 'editPlaylistTitle' => __('Edit Audio Playlist'), 'cancelPlaylistTitle' => __('&#8592; Cancel Audio Playlist'), 'insertPlaylist' => __('Insert audio playlist'), 'updatePlaylist' => __('Update audio playlist'), 'addToPlaylist' => __('Add to audio playlist'), 'addToPlaylistTitle' => __('Add to Audio Playlist'), 'videoPlaylistDragInfo' => __('Drag and drop to reorder videos.'), 'createVideoPlaylistTitle' => __('Create Video Playlist'), 'editVideoPlaylistTitle' => __('Edit Video Playlist'), 'cancelVideoPlaylistTitle' => __('&#8592; Cancel Video Playlist'), 'insertVideoPlaylist' => __('Insert video playlist'), 'updateVideoPlaylist' => __('Update video playlist'), 'addToVideoPlaylist' => __('Add to video playlist'), 'addToVideoPlaylistTitle' => __('Add to Video Playlist'));
    /**
     * Filter the media view settings.
     *
     * @since 0.0.1
     *
     * @param array   $settings List of media view settings.
     * @param HQ_Post $post     Post object.
     */
    $settings = apply_filters('media_view_settings', $settings, $post);
    /**
     * Filter the media view strings.
     *
     * @since 0.0.1
     *
     * @param array   $strings List of media view strings.
     * @param HQ_Post $post    Post object.
     */
    $strings = apply_filters('media_view_strings', $strings, $post);
    $strings['settings'] = $settings;
    // Ensure we enqueue media-editor first, that way media-views is
    // registered internally before we try to localize it. see #24724.
    hq_enqueue_script('media-editor');
    hq_localize_script('media-views', '_hqMediaViewsL10n', $strings);
    hq_enqueue_script('media-audiovideo');
    hq_enqueue_style('media-views');
    if (is_admin()) {
        hq_enqueue_script('mce-view');
        hq_enqueue_script('image-edit');
    }
    hq_enqueue_style('imgareaselect');
    hq_plupload_default_settings();
    require_once ABSPATH . HQINC . '/media-template.php';
    add_action('admin_footer', 'hq_print_media_templates');
    add_action('hq_footer', 'hq_print_media_templates');
    add_action('customize_controls_print_footer_scripts', 'hq_print_media_templates');
    /**
     * Fires at the conclusion of hq_enqueue_media().
     *
     * @since 0.0.1
     */
    do_action('hq_enqueue_media');
}
Пример #6
0
/**
 * Check nonce expiration on the New/Edit Post screen and refresh if needed
 *
 * @since 0.0.1
 */
function hq_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('hq-refresh-post-nonces', $data)) {
        $received = $data['hq-refresh-post-nonces'];
        $response['hq-refresh-post-nonces'] = array('check' => 1);
        if (!($post_id = absint($received['post_id']))) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id)) {
            return $response;
        }
        $response['hq-refresh-post-nonces'] = array('replace' => array('getpermalinknonce' => hq_create_nonce('getpermalink'), 'samplepermalinknonce' => hq_create_nonce('samplepermalink'), 'closedpostboxesnonce' => hq_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => hq_create_nonce('internal-linking'), '_hqnonce' => hq_create_nonce('update-post_' . $post_id)), 'heartbeatNonce' => hq_create_nonce('heartbeat-nonce'));
    }
    return $response;
}
Пример #7
0
    /**
     * Display first step of custom header image page.
     *
     * @since 0.0.1
     */
    public function step_1()
    {
        $this->process_default_headers();
        ?>

<div class="wrap">
<h1><?php 
        _e('Custom Header');
        ?>
</h1>

<?php 
        if (current_user_can('customize')) {
            ?>
<div class="notice notice-info hide-if-no-customize">
	<p>
		<?php 
            printf(__('You can now manage and live-preview Custom Header in the <a href="%1$s">Customizer</a>.'), admin_url('customize.php?autofocus[control]=header_image'));
            ?>
	</p>
</div>
<?php 
        }
        ?>

<?php 
        if (!empty($this->updated)) {
            ?>
<div id="message" class="updated">
<p><?php 
            printf(__('Header updated. <a href="%s">Visit your site</a> to see how it looks.'), home_url('/'));
            ?>
</p>
</div>
<?php 
        }
        ?>

<h3><?php 
        _e('Header Image');
        ?>
</h3>

<table class="form-table">
<tbody>

<?php 
        if (get_custom_header() || display_header_text()) {
            ?>
<tr>
<th scope="row"><?php 
            _e('Preview');
            ?>
</th>
<td>
	<?php 
            if ($this->admin_image_div_callback) {
                call_user_func($this->admin_image_div_callback);
            } else {
                $custom_header = get_custom_header();
                $header_image = get_header_image();
                if ($header_image) {
                    $header_image_style = 'background-image:url(' . esc_url($header_image) . ');';
                } else {
                    $header_image_style = '';
                }
                if ($custom_header->width) {
                    $header_image_style .= 'max-width:' . $custom_header->width . 'px;';
                }
                if ($custom_header->height) {
                    $header_image_style .= 'height:' . $custom_header->height . 'px;';
                }
                ?>
	<div id="headimg" style="<?php 
                echo $header_image_style;
                ?>
">
		<?php 
                if (display_header_text()) {
                    $style = ' style="color:#' . get_header_textcolor() . ';"';
                } else {
                    $style = ' style="display:none;"';
                }
                ?>
		<h1><a id="name" class="displaying-header-text" <?php 
                echo $style;
                ?>
 onclick="return false;" href="<?php 
                bloginfo('url');
                ?>
" tabindex="-1"><?php 
                bloginfo('name');
                ?>
</a></h1>
		<div id="desc" class="displaying-header-text" <?php 
                echo $style;
                ?>
><?php 
                bloginfo('description');
                ?>
</div>
	</div>
	<?php 
            }
            ?>
</td>
</tr>
<?php 
        }
        ?>

<?php 
        if (current_user_can('upload_files') && current_theme_supports('custom-header', 'uploads')) {
            ?>
<tr>
<th scope="row"><?php 
            _e('Select Image');
            ?>
</th>
<td>
	<p><?php 
            _e('You can select an image to be shown at the top of your site by uploading from your computer or choosing from your media library. After selecting an image you will be able to crop it.');
            ?>
<br />
	<?php 
            if (!current_theme_supports('custom-header', 'flex-height') && !current_theme_supports('custom-header', 'flex-width')) {
                printf(__('Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.') . '<br />', get_theme_support('custom-header', 'width'), get_theme_support('custom-header', 'height'));
            } elseif (current_theme_supports('custom-header', 'flex-height')) {
                if (!current_theme_supports('custom-header', 'flex-width')) {
                    printf(__('Images should be at least <strong>%1$d pixels</strong> wide.') . ' ', get_theme_support('custom-header', 'width'));
                }
            } elseif (current_theme_supports('custom-header', 'flex-width')) {
                if (!current_theme_supports('custom-header', 'flex-height')) {
                    printf(__('Images should be at least <strong>%1$d pixels</strong> tall.') . ' ', get_theme_support('custom-header', 'height'));
                }
            }
            if (current_theme_supports('custom-header', 'flex-height') || current_theme_supports('custom-header', 'flex-width')) {
                if (current_theme_supports('custom-header', 'width')) {
                    printf(__('Suggested width is <strong>%1$d pixels</strong>.') . ' ', get_theme_support('custom-header', 'width'));
                }
                if (current_theme_supports('custom-header', 'height')) {
                    printf(__('Suggested height is <strong>%1$d pixels</strong>.') . ' ', get_theme_support('custom-header', 'height'));
                }
            }
            ?>
</p>
	<form enctype="multipart/form-data" id="upload-form" class="hq-upload-form" method="post" action="<?php 
            echo esc_url(add_query_arg('step', 2));
            ?>
">
	<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 
            hq_nonce_field('custom-header-upload', '_hqnonce-custom-header-upload');
            ?>
		<?php 
            submit_button(__('Upload'), 'button', 'submit', false);
            ?>
	</p>
	<?php 
            $modal_update_href = esc_url(add_query_arg(array('page' => 'custom-header', 'step' => 2, '_hqnonce-custom-header-upload' => hq_create_nonce('custom-header-upload')), admin_url('themes.php')));
            ?>
	<p>
		<label for="choose-from-library-link"><?php 
            _e('Or choose an image from your media library:');
            ?>
</label><br />
		<button id="choose-from-library-link" class="button"
			data-update-link="<?php 
            echo esc_attr($modal_update_href);
            ?>
"
			data-choose="<?php 
            esc_attr_e('Choose a Custom Header');
            ?>
"
			data-update="<?php 
            esc_attr_e('Set as header');
            ?>
"><?php 
            _e('Choose Image');
            ?>
</button>
	</p>
	</form>
</td>
</tr>
<?php 
        }
        ?>
</tbody>
</table>

<form method="post" action="<?php 
        echo esc_url(add_query_arg('step', 1));
        ?>
">
<?php 
        submit_button(null, 'screen-reader-text', 'save-header-options', false);
        ?>
<table class="form-table">
<tbody>
	<?php 
        if (get_uploaded_header_images()) {
            ?>
<tr>
<th scope="row"><?php 
            _e('Uploaded Images');
            ?>
</th>
<td>
	<p><?php 
            _e('You can choose one of your previously uploaded headers, or show a random one.');
            ?>
</p>
	<?php 
            $this->show_header_selector('uploaded');
            ?>
</td>
</tr>
	<?php 
        }
        if (!empty($this->default_headers)) {
            ?>
<tr>
<th scope="row"><?php 
            _e('Default Images');
            ?>
</th>
<td>
<?php 
            if (current_theme_supports('custom-header', 'uploads')) {
                ?>
	<p><?php 
                _e('If you don&lsquo;t want to upload your own image, you can use one of these cool headers, or show a random one.');
                ?>
</p>
<?php 
            } else {
                ?>
	<p><?php 
                _e('You can use one of these cool headers or show a random one on each page.');
                ?>
</p>
<?php 
            }
            ?>
	<?php 
            $this->show_header_selector('default');
            ?>
</td>
</tr>
	<?php 
        }
        if (get_header_image()) {
            ?>
<tr>
<th scope="row"><?php 
            _e('Remove Image');
            ?>
</th>
<td>
	<p><?php 
            _e('This will remove the header image. You will not be able to restore any customizations.');
            ?>
</p>
	<?php 
            submit_button(__('Remove Header Image'), 'button', 'removeheader', false);
            ?>
</td>
</tr>
	<?php 
        }
        $default_image = get_theme_support('custom-header', 'default-image');
        if ($default_image && get_header_image() != $default_image) {
            ?>
<tr>
<th scope="row"><?php 
            _e('Reset Image');
            ?>
</th>
<td>
	<p><?php 
            _e('This will restore the original header image. You will not be able to restore any customizations.');
            ?>
</p>
	<?php 
            submit_button(__('Restore Original Header Image'), 'button', 'resetheader', false);
            ?>
</td>
</tr>
	<?php 
        }
        ?>
</tbody>
</table>

<?php 
        if (current_theme_supports('custom-header', 'header-text')) {
            ?>

<h3><?php 
            _e('Header Text');
            ?>
</h3>

<table class="form-table">
<tbody>
<tr>
<th scope="row"><?php 
            _e('Header Text');
            ?>
</th>
<td>
	<p>
	<label><input type="checkbox" name="display-header-text" id="display-header-text"<?php 
            checked(display_header_text());
            ?>
 /> <?php 
            _e('Show header text with your image.');
            ?>
</label>
	</p>
</td>
</tr>

<tr class="displaying-header-text">
<th scope="row"><?php 
            _e('Text Color');
            ?>
</th>
<td>
	<p>
	<?php 
            $default_color = '';
            if (current_theme_supports('custom-header', 'default-text-color')) {
                $default_color = get_theme_support('custom-header', 'default-text-color');
                if ($default_color && false === strpos($default_color, '#')) {
                    $default_color = '#' . $default_color;
                }
            }
            $default_color_attr = $default_color ? ' data-default-color="' . esc_attr($default_color) . '"' : '';
            $header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support('custom-header', 'default-text-color');
            if ($header_textcolor && false === strpos($header_textcolor, '#')) {
                $header_textcolor = '#' . $header_textcolor;
            }
            echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr($header_textcolor) . '"' . $default_color_attr . ' />';
            if ($default_color) {
                echo ' <span class="description hide-if-js">' . sprintf(_x('Default: %s', 'color'), esc_html($default_color)) . '</span>';
            }
            ?>
	</p>
</td>
</tr>
</tbody>
</table>
<?php 
        }
        /**
         * Fires just before the submit button in the custom header options form.
         *
         * @since 0.0.1
         */
        do_action('custom_header_options');
        hq_nonce_field('custom-header-options', '_hqnonce-custom-header-options');
        ?>

<?php 
        submit_button(null, 'primary', 'save-header-options');
        ?>
</form>
</div>

<?php 
    }
Пример #8
0
/**
 * Attempts activation of plugin in a "sandbox" and redirects on success.
 *
 * A plugin that is already activated will not attempt to be activated again.
 *
 * The way it works is by setting the redirection to the error before trying to
 * include the plugin file. If the plugin fails, then the redirection will not
 * be overwritten with the success message. Also, the options will not be
 * updated and the activation hook will not be called on plugin error.
 *
 * It should be noted that in no way the below code will actually prevent errors
 * within the file. The code should not be used elsewhere to replicate the
 * "sandbox", which uses redirection to work.
 * {@source 13 1}
 *
 * If any errors are found or text is outputted, then it will be captured to
 * ensure that the success redirection will update the error redirection.
 *
 * @since 0.0.1
 *
 * @param string $plugin Plugin path to main plugin file with plugin data.
 * @param string $redirect Optional. URL to redirect to.
 * @param bool $network_wide Whether to enable the plugin for all sites in the
 *   network or just the current site. Multisite only. Default is false.
 * @param bool $silent Prevent calling activation hooks. Optional, default is false.
 * @return HQ_Error|null HQ_Error on invalid file or null on success.
 */
function activate_plugin($plugin, $redirect = '', $network_wide = false, $silent = false)
{
    $plugin = plugin_basename(trim($plugin));
    if (is_multisite() && ($network_wide || is_network_only_plugin($plugin))) {
        $network_wide = true;
        $current = get_site_option('active_sitewide_plugins', array());
        $_GET['networkwide'] = 1;
        // Back compat for plugins looking for this value.
    } else {
        $current = get_option('active_plugins', array());
    }
    $valid = validate_plugin($plugin);
    if (is_hq_error($valid)) {
        return $valid;
    }
    if ($network_wide && !isset($current[$plugin]) || !$network_wide && !in_array($plugin, $current)) {
        if (!empty($redirect)) {
            hq_redirect(add_query_arg('_error_nonce', hq_create_nonce('plugin-activation-error_' . $plugin), $redirect));
        }
        // we'll override this later if the plugin can be included without fatal error
        ob_start();
        hq_register_plugin_realpath(HQ_PLUGIN_DIR . '/' . $plugin);
        $_hq_plugin_file = $plugin;
        include_once HQ_PLUGIN_DIR . '/' . $plugin;
        $plugin = $_hq_plugin_file;
        // Avoid stomping of the $plugin variable in a plugin.
        if (!$silent) {
            /**
             * Fires before a plugin is activated.
             *
             * If a plugin is silently activated (such as during an update),
             * this hook does not fire.
             *
             * @since 0.0.1
             *
             * @param string $plugin       Plugin path to main plugin file with plugin data.
             * @param bool   $network_wide Whether to enable the plugin for all sites in the network
             *                             or just the current site. Multisite only. Default is false.
             */
            do_action('activate_plugin', $plugin, $network_wide);
            /**
             * Fires as a specific plugin is being activated.
             *
             * This hook is the "activation" hook used internally by
             * {@see register_activation_hook()}. The dynamic portion of the
             * hook name, `$plugin`, refers to the plugin basename.
             *
             * If a plugin is silently activated (such as during an update),
             * this hook does not fire.
             *
             * @since 0.0.1
             *
             * @param bool $network_wide Whether to enable the plugin for all sites in the network
             *                           or just the current site. Multisite only. Default is false.
             */
            do_action('activate_' . $plugin, $network_wide);
        }
        if ($network_wide) {
            $current = get_site_option('active_sitewide_plugins', array());
            $current[$plugin] = time();
            update_site_option('active_sitewide_plugins', $current);
        } else {
            $current = get_option('active_plugins', array());
            $current[] = $plugin;
            sort($current);
            update_option('active_plugins', $current);
        }
        if (!$silent) {
            /**
             * Fires after a plugin has been activated.
             *
             * If a plugin is silently activated (such as during an update),
             * this hook does not fire.
             *
             * @since 0.0.1
             *
             * @param string $plugin       Plugin path to main plugin file with plugin data.
             * @param bool   $network_wide Whether to enable the plugin for all sites in the network
             *                             or just the current site. Multisite only. Default is false.
             */
            do_action('activated_plugin', $plugin, $network_wide);
        }
        if (ob_get_length() > 0) {
            $output = ob_get_clean();
            return new HQ_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
        }
        ob_end_clean();
    }
    return null;
}