PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.6.4
Jetpack – WP Security, Backup, Speed, & Growth v3.6.4
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / notes.php

notes.php in Jetpack – WP Security, Backup, Speed, & Growth 3.6.4, at modules/notes.php

185 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Module Name: Notifications
4 * Module Description: Receive notification of site activity via the admin toolbar and your Mobile devices.
5 * Sort Order: 13
6 * First Introduced: 1.9
7 * Requires Connection: Yes
8 * Auto Activate: Yes
9 * Module Tags: Other
10 */
11
12 if ( !defined( 'JETPACK_NOTES__CACHE_BUSTER' ) ) define( 'JETPACK_NOTES__CACHE_BUSTER', JETPACK__VERSION . '-' . gmdate( 'oW' ) );
13
14 Jetpack_Sync::sync_options( __FILE__,
15 'home',
16 'blogname',
17 'siteurl',
18 'permalink_structure',
19 'category_base',
20 'tag_base',
21 'comment_moderation',
22 'default_comment_status',
23 'thread_comments',
24 'thread_comments_depth'
25 );
26
27 class Jetpack_Notifications {
28 var $jetpack = false;
29
30 /**
31 * Singleton
32 * @static
33 */
34 public static function init() {
35 static $instance = array();
36
37 if ( !$instance ) {
38 $instance[0] = new Jetpack_Notifications;
39 }
40
41 return $instance[0];
42 }
43
44 function __construct() {
45 $this->jetpack = Jetpack::init();
46
47 add_action( 'init', array( &$this, 'action_init' ) );
48 }
49
50 function wpcom_static_url($file) {
51 $i = hexdec( substr( md5( $file ), -1 ) ) % 2;
52 $url = 'http://s' . $i . '.wp.com' . $file;
53 return set_url_scheme( $url );
54 }
55
56 // return the major version of Internet Explorer the viewer is using or false if it's not IE
57 public static function get_internet_explorer_version() {
58 static $version;
59 if ( isset( $version ) ) {
60 return $version;
61 }
62
63 $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
64
65 preg_match( '/MSIE (\d+)/', $user_agent, $matches );
66 $version = empty( $matches[1] ) ? null : $matches[1];
67 if ( empty( $version ) || !$version ) {
68 return false;
69 }
70 return $version;
71 }
72
73 public static function current_browser_is_supported() {
74 static $supported;
75
76 if ( isset( $supported ) ) {
77 return $supported;
78 }
79
80 $ie_version = self::get_internet_explorer_version();
81 if ( false === $ie_version ) {
82 return $supported = true;
83 }
84
85 if ( $ie_version < 8 ) {
86 return $supported = false;
87 }
88
89 return $supported = true;
90 }
91
92 function action_init() {
93 //syncing must wait until after init so
94 //post types that support comments
95 $filt_post_types = array();
96 $all_post_types = get_post_types();
97 foreach ( $all_post_types as $post_type ) {
98 if ( post_type_supports( $post_type, 'comments' ) ) {
99 $filt_post_types[] = $post_type;
100 }
101 }
102
103 Jetpack_Sync::sync_posts( __FILE__, array(
104 'post_types' => $filt_post_types,
105 'post_stati' => array( 'publish' ),
106 ) );
107 Jetpack_Sync::sync_comments( __FILE__, array(
108 'post_types' => $filt_post_types,
109 'post_stati' => array( 'publish' ),
110 'comment_stati' => array( 'approve', 'approved', '1', 'hold', 'unapproved', 'unapprove', '0', 'spam', 'trash' ),
111 ) );
112
113 if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
114 return;
115
116 if ( !has_filter( 'show_admin_bar', '__return_true' ) && !is_user_logged_in() )
117 return;
118
119 if ( !self::current_browser_is_supported() )
120 return;
121
122 add_action( 'admin_bar_menu', array( &$this, 'admin_bar_menu'), 120 );
123 add_action( 'wp_head', array( &$this, 'styles_and_scripts'), 120 );
124 add_action( 'admin_head', array( &$this, 'styles_and_scripts') );
125 }
126
127 function styles_and_scripts() {
128 wp_enqueue_style( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/admin-bar-v2.css' ), array(), JETPACK_NOTES__CACHE_BUSTER );
129 wp_enqueue_style( 'noticons', $this->wpcom_static_url( '/i/noticons/noticons.css' ), array(), JETPACK_NOTES__CACHE_BUSTER );
130
131 $this->print_js();
132
133 // attempt to use core or plugin libraries if registered
134 if ( !wp_script_is( 'mustache', 'registered' ) ) {
135 wp_register_script( 'mustache', $this->wpcom_static_url( '/wp-content/js/mustache.js' ), null, JETPACK_NOTES__CACHE_BUSTER );
136 }
137 if ( !wp_script_is( 'underscore', 'registered' ) ) {
138 wp_register_script( 'underscore', $this->wpcom_static_url( '/wp-includes/js/underscore.min.js' ), null, JETPACK_NOTES__CACHE_BUSTER );
139 }
140 if ( !wp_script_is( 'backbone', 'registered' ) ) {
141 wp_register_script( 'backbone', $this->wpcom_static_url( '/wp-includes/js/backbone.min.js' ), array( 'underscore' ), JETPACK_NOTES__CACHE_BUSTER );
142 }
143
144 wp_register_script( 'wpcom-notes-common', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/notes-common-v2.js' ), array( 'jquery', 'underscore', 'backbone', 'mustache' ), JETPACK_NOTES__CACHE_BUSTER );
145 wp_enqueue_script( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/admin-bar-v2.js' ), array( 'wpcom-notes-common' ), JETPACK_NOTES__CACHE_BUSTER );
146 }
147
148 function admin_bar_menu() {
149 global $wp_admin_bar, $current_blog;
150
151 if ( !is_object( $wp_admin_bar ) )
152 return;
153
154 $classes = 'wpnt-loading wpn-read';
155 $wp_admin_bar->add_menu( array(
156 'id' => 'notes',
157 'title' => '<span id="wpnt-notes-unread-count" class="' . esc_attr( $classes ) . '">
158 <span class="noticon noticon-notification"></span>
159 </span>',
160 'meta' => array(
161 'html' => '<div id="wpnt-notes-panel" style="display:none" lang="'. esc_attr( get_locale() ) . '" dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"><div class="wpnt-notes-panel-header"><span class="wpnt-notes-header">' . __( 'Notifications', 'jetpack' ) . '</span><span class="wpnt-notes-panel-link"></span></div></div>',
162 'class' => 'menupop',
163 ),
164 'parent' => 'top-secondary',
165 ) );
166 }
167
168 function print_js() {
169 $link_accounts_url = is_user_logged_in() && !Jetpack::is_user_connected() ? Jetpack::admin_url() : false;
170 ?>
171 <script type="text/javascript">
172 /* <![CDATA[ */
173 var wpNotesIsJetpackClient = true;
174 <?php if ( $link_accounts_url ) : ?>
175 var wpNotesLinkAccountsURL = '<?php print $link_accounts_url; ?>';
176 <?php endif; ?>
177 /* ]]> */
178 </script>
179 <?php
180 }
181
182 }
183
184 Jetpack_Notifications::init();
185