Exemplo n.º 1
0
    /**
     * Print the pointer JavaScript data.
     *
     * @since 0.0.1
     *
     * @static
     *
     * @param string $pointer_id The pointer ID.
     * @param string $selector The HTML elements, on which the pointer should be attached.
     * @param array  $args Arguments to be passed to the pointer JS (see hq-pointer.js).
     */
    private static function print_js($pointer_id, $selector, $args)
    {
        if (empty($pointer_id) || empty($selector) || empty($args) || empty($args['content'])) {
            return;
        }
        ?>
		<script type="text/javascript">
		(function($){
			var options = <?php 
        echo hq_json_encode($args);
        ?>
, setup;

			if ( ! options )
				return;

			options = $.extend( options, {
				close: function() {
					$.post( ajaxurl, {
						pointer: '<?php 
        echo $pointer_id;
        ?>
',
						action: 'dismiss-hq-pointer'
					});
				}
			});

			setup = function() {
				$('<?php 
        echo $selector;
        ?>
').first().pointer( options ).pointer('open');
			};

			if ( options.position && options.position.defer_loading )
				$(window).bind( 'load.hq-pointers', setup );
			else
				$(document).ready( setup );

		})( jQuery );
		</script>
		<?php 
    }
Exemplo n.º 2
0
/**
 * Retrieve the Press This bookmarklet link.
 *
 * Use this in 'a' element 'href' attribute.
 *
 * @since 0.0.1
 *
 * @global bool          $is_IE
 * @global string        $hq_version
 * @global HQ_Press_This $hq_press_this
 *
 * @return string The Press This bookmarklet link URL.
 */
function get_shortcut_link()
{
    global $is_IE, $hq_version;
    include_once ABSPATH . 'hq-admin/includes/class-hq-press-this.php';
    $bookmarklet_version = $GLOBALS['hq_press_this']->version;
    $link = '';
    if ($is_IE) {
        /**
         * Return the old/shorter bookmarklet code for MSIE 8 and lower,
         * since they only support a max length of ~2000 characters for
         * bookmark[let] URLs, which is way to small for our smarter one.
         * Do update the version number so users do not get the "upgrade your
         * bookmarklet" notice when using PT in those browsers.
         */
        $ua = $_SERVER['HTTP_USER_AGENT'];
        if (!empty($ua) && preg_match('/\\bMSIE (\\d)/', $ua, $matches) && (int) $matches[1] <= 8) {
            $url = hq_json_encode(admin_url('press-this.php'));
            $link = 'javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,' . 's=(e?e():(k)?k():(x?x.createRange().text:0)),f=' . $url . ',l=d.location,e=encodeURIComponent,' . 'u=f+"?u="+e(l.href)+"&t="+e(d.title)+"&s="+e(s)+"&v=' . $bookmarklet_version . '";' . 'a=function(){if(!w.open(u,"t","toolbar=0,resizable=1,scrollbars=1,status=1,width=600,height=700"))l.href=u;};' . 'if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();void(0)';
        }
    }
    if (empty($link)) {
        $src = @file_get_contents(ABSPATH . 'hq-admin/js/bookmarklet.min.js');
        if ($src) {
            $url = hq_json_encode(admin_url('press-this.php') . '?v=' . $bookmarklet_version);
            $link = 'javascript:' . str_replace('window.pt_url', $url, $src);
        }
    }
    $link = str_replace(array("\r", "\n", "\t"), '', $link);
    /**
     * Filter the Press This bookmarklet link.
     *
     * @since 0.0.1
     *
     * @param string $link The Press This bookmarklet link.
     */
    return apply_filters('shortcut_link', $link);
}
Exemplo n.º 3
0
/**
 *
 * @global string $hq_version
 * @staticvar bool $printed
 */
function print_emoji_detection_script()
{
    global $hq_version;
    static $printed = false;
    if ($printed) {
        return;
    }
    $printed = true;
    $settings = array('baseUrl' => apply_filters('emoji_url', set_url_scheme('//s.w.org/images/core/emoji/72x72/')), 'ext' => apply_filters('emoji_ext', '.png'));
    $version = 'ver=' . $hq_version;
    if (SCRIPT_DEBUG) {
        $settings['source'] = array('hqemoji' => apply_filters('script_loader_src', includes_url("js/hq-emoji.js?{$version}"), 'hqemoji'), 'twemoji' => apply_filters('script_loader_src', includes_url("js/twemoji.js?{$version}"), 'twemoji'));
        ?>
		<script type="text/javascript">
			window._wpemojiSettings = <?php 
        echo hq_json_encode($settings);
        ?>
;
			<?php 
        readfile(ABSPATH . HQINC . "/js/hq-emoji-loader.js");
        ?>
		</script>
		<?php 
    } else {
        $settings['source'] = array('concatemoji' => apply_filters('script_loader_src', includes_url("js/hq-emoji-release.min.js?{$version}"), 'concatemoji'));
        /*
         * If you're looking at a src version of this file, you'll see an "include"
         * statement below. This is used by the `grunt build` process to directly
         * include a minified version of hq-emoji-loader.js, instead of using the
         * readfile() method from above.
         *
         * If you're looking at a build version of this file, you'll see a string of
         * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
         * and edit hq-emoji-loader.js directly.
         */
        ?>
		<script type="text/javascript">
			window._wpemojiSettings = <?php 
        echo hq_json_encode($settings);
        ?>
;
			!function(a,b,c){function d(a){var c=b.createElement("canvas"),d=c.getContext&&c.getContext("2d");return d&&d.fillText?(d.textBaseline="top",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
		</script>
		<?php 
    }
}
Exemplo n.º 4
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.º 5
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);
}
Exemplo n.º 6
0
/**
 *
 * @global array $_hq_admin_css_colors
 */
function hq_color_scheme_settings()
{
    global $_hq_admin_css_colors;
    $color_scheme = get_user_option('admin_color');
    // It's possible to have a color scheme set that is no longer registered.
    if (empty($_hq_admin_css_colors[$color_scheme])) {
        $color_scheme = 'fresh';
    }
    if (!empty($_hq_admin_css_colors[$color_scheme]->icon_colors)) {
        $icon_colors = $_hq_admin_css_colors[$color_scheme]->icon_colors;
    } elseif (!empty($_hq_admin_css_colors['fresh']->icon_colors)) {
        $icon_colors = $_hq_admin_css_colors['fresh']->icon_colors;
    } else {
        // Fall back to the default set of icon colors if the default scheme is missing.
        $icon_colors = array('base' => '#999', 'focus' => '#00a0d2', 'current' => '#fff');
    }
    echo '<script type="text/javascript">var _hqColorScheme = ' . hq_json_encode(array('icons' => $icon_colors)) . ";</script>\n";
}
Exemplo n.º 7
0
 /**
  * Localizes a script, only if the script has already been added
  *
  * @param string $handle
  * @param string $object_name
  * @param array $l10n
  * @return bool
  */
 public function localize($handle, $object_name, $l10n)
 {
     if ($handle === 'jquery') {
         $handle = 'jquery-core';
     }
     if (is_array($l10n) && isset($l10n['l10n_print_after'])) {
         // back compat, preserve the code in 'l10n_print_after' if present
         $after = $l10n['l10n_print_after'];
         unset($l10n['l10n_print_after']);
     }
     foreach ((array) $l10n as $key => $value) {
         if (!is_scalar($value)) {
             continue;
         }
         $l10n[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
     }
     $script = "var {$object_name} = " . hq_json_encode($l10n) . ';';
     if (!empty($after)) {
         $script .= "\n{$after};";
     }
     $data = $this->get_data($handle, 'data');
     if (!empty($data)) {
         $script = "{$data}\n{$script}";
     }
     return $this->add_data($handle, 'data', $script);
 }