Exemplo n.º 1
0
/**
 * Prints the script queue in the HTML head on admin pages.
 *
 * Postpones the scripts that were queued for the footer.
 * print_footer_scripts() is called in the footer to print these scripts.
 *
 * @since 0.0.1
 *
 * @see hq_print_scripts()
 *
 * @global bool $concatenate_scripts
 *
 * @return array
 */
function print_head_scripts()
{
    global $concatenate_scripts;
    if (!did_action('hq_print_scripts')) {
        /** This action is documented in hq-includes/functions.hq-scripts.php */
        do_action('hq_print_scripts');
    }
    $hq_scripts = hq_scripts();
    script_concat_settings();
    $hq_scripts->do_concat = $concatenate_scripts;
    $hq_scripts->do_head_items();
    /**
     * Filter whether to print the head scripts.
     *
     * @since 0.0.1
     *
     * @param bool $print Whether to print the head scripts. Default true.
     */
    if (apply_filters('print_head_scripts', true)) {
        _print_scripts();
    }
    $hq_scripts->reset();
    return $hq_scripts->done;
}
Exemplo n.º 2
0
/**
 * Adds settings for the customize-loader script.
 *
 * @since 0.0.1
 */
function _hq_customize_loader_settings()
{
    $admin_origin = parse_url(admin_url());
    $home_origin = parse_url(home_url());
    $cross_domain = strtolower($admin_origin['host']) != strtolower($home_origin['host']);
    $browser = array('mobile' => hq_is_mobile(), 'ios' => hq_is_mobile() && preg_match('/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT']));
    $settings = array('url' => esc_url(admin_url('customize.php')), 'isCrossDomain' => $cross_domain, 'browser' => $browser, 'l10n' => array('saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), 'mainIframeTitle' => __('Customizer')));
    $script = 'var _hqCustomizeLoaderSettings = ' . hq_json_encode($settings) . ';';
    $hq_scripts = hq_scripts();
    $data = $hq_scripts->get_data('customize-loader', 'data');
    if ($data) {
        $script = "{$data}\n{$script}";
    }
    $hq_scripts->add_data('customize-loader', 'data', $script);
}
Exemplo n.º 3
0
/**
 * Add metadata to a script.
 *
 * Works only if the script has already been added.
 *
 * Possible values for $key and $value:
 * 'conditional' string Comments for IE 6, lte IE 7, etc.
 *
 * @since 0.0.1
 *
 * @see HQ_Dependency::add_data()
 *
 * @param string $handle Name of the script.
 * @param string $key    Name of data point for which we're storing a value.
 * @param mixed  $value  String containing the data to be added.
 * @return bool True on success, false on failure.
 */
function hq_script_add_data($handle, $key, $value)
{
    return hq_scripts()->add_data($handle, $key, $value);
}
Exemplo n.º 4
0
/**
 * Prints default plupload arguments.
 *
 * @since 0.0.1
 */
function hq_plupload_default_settings()
{
    $hq_scripts = hq_scripts();
    $data = $hq_scripts->get_data('hq-plupload', 'data');
    if ($data && false !== strpos($data, '_hqPluploadSettings')) {
        return;
    }
    $max_upload_size = hq_max_upload_size();
    $defaults = array('runtimes' => 'html5,flash,silverlight,html4', 'file_data_name' => 'async-upload', 'url' => admin_url('async-upload.php', 'relative'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array('max_file_size' => $max_upload_size . 'b'));
    // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos
    // when enabled. See #29602.
    if (hq_is_mobile() && strpos($_SERVER['HTTP_USER_AGENT'], 'OS 7_') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'like Mac OS X') !== false) {
        $defaults['multi_selection'] = false;
    }
    /**
     * Filter the Plupload default settings.
     *
     * @since 0.0.1
     *
     * @param array $defaults Default Plupload settings array.
     */
    $defaults = apply_filters('plupload_default_settings', $defaults);
    $params = array('action' => 'upload-attachment');
    /**
     * Filter the Plupload default parameters.
     *
     * @since 0.0.1
     *
     * @param array $params Default Plupload parameters array.
     */
    $params = apply_filters('plupload_default_params', $params);
    $params['_hqnonce'] = hq_create_nonce('media-form');
    $defaults['multipart_params'] = $params;
    $settings = array('defaults' => $defaults, 'browser' => array('mobile' => hq_is_mobile(), 'supported' => _device_can_upload()), 'limitExceeded' => is_multisite() && !is_upload_space_available());
    $script = 'var _hqPluploadSettings = ' . hq_json_encode($settings) . ';';
    if ($data) {
        $script = "{$data}\n{$script}";
    }
    $hq_scripts->add_data('hq-plupload', 'data', $script);
}