PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.0.6
Jetpack – WP Security, Backup, Speed, & Growth v3.0.6
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.0.6, at modules/notes.php

183 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 Jetpack_Notifications() {
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 preg_match( '/MSIE (\d+)/', $_SERVER['HTTP_USER_AGENT'], $matches );
64 $version = empty( $matches[1] ) ? null : $matches[1];
65 if ( empty( $version ) || !$version ) {
66 return false;
67 }
68 return $version;
69 }
70
71 public static function current_browser_is_supported() {
72 static $supported;
73
74 if ( isset( $supported ) ) {
75 return $supported;
76 }
77
78 $ie_version = self::get_internet_explorer_version();
79 if ( false === $ie_version ) {
80 return $supported = true;
81 }
82
83 if ( $ie_version < 8 ) {
84 return $supported = false;
85 }
86
87 return $supported = true;
88 }
89
90 function action_init() {
91 //syncing must wait until after init so
92 //post types that support comments
93 $filt_post_types = array();
94 $all_post_types = get_post_types();
95 foreach ( $all_post_types as $post_type ) {
96 if ( post_type_supports( $post_type, 'comments' ) ) {
97 $filt_post_types[] = $post_type;
98 }
99 }
100
101 Jetpack_Sync::sync_posts( __FILE__, array(
102 'post_types' => $filt_post_types,
103 'post_stati' => array( 'publish' ),
104 ) );
105 Jetpack_Sync::sync_comments( __FILE__, array(
106 'post_types' => $filt_post_types,
107 'post_stati' => array( 'publish' ),
108 'comment_stati' => array( 'approve', 'approved', '1', 'hold', 'unapproved', 'unapprove', '0', 'spam', 'trash' ),
109 ) );
110
111 if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
112 return;
113
114 if ( !has_filter( 'show_admin_bar', '__return_true' ) && !is_user_logged_in() )
115 return;
116
117 if ( !self::current_browser_is_supported() )
118 return;
119
120 add_action( 'admin_bar_menu', array( &$this, 'admin_bar_menu'), 120 );
121 add_action( 'wp_head', array( &$this, 'styles_and_scripts'), 120 );
122 add_action( 'admin_head', array( &$this, 'styles_and_scripts') );
123 }
124
125 function styles_and_scripts() {
126 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 );
127 wp_enqueue_style( 'noticons', $this->wpcom_static_url( '/i/noticons/noticons.css' ), array(), JETPACK_NOTES__CACHE_BUSTER );
128
129 $this->print_js();
130
131 // attempt to use core or plugin libraries if registered
132 if ( !wp_script_is( 'mustache', 'registered' ) ) {
133 wp_register_script( 'mustache', $this->wpcom_static_url( '/wp-content/js/mustache.js' ), null, JETPACK_NOTES__CACHE_BUSTER );
134 }
135 if ( !wp_script_is( 'underscore', 'registered' ) ) {
136 wp_register_script( 'underscore', $this->wpcom_static_url( '/wp-includes/js/underscore.min.js' ), null, JETPACK_NOTES__CACHE_BUSTER );
137 }
138 if ( !wp_script_is( 'backbone', 'registered' ) ) {
139 wp_register_script( 'backbone', $this->wpcom_static_url( '/wp-includes/js/backbone.min.js' ), array( 'underscore' ), JETPACK_NOTES__CACHE_BUSTER );
140 }
141
142 wp_register_script( 'wpcom-notes-common', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/notes-common-v2.js' ), array( 'jquery', 'underscore', 'backbone', 'mustache', 'jquery.spin' ), JETPACK_NOTES__CACHE_BUSTER );
143 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 );
144 }
145
146 function admin_bar_menu() {
147 global $wp_admin_bar, $current_blog;
148
149 if ( !is_object( $wp_admin_bar ) )
150 return;
151
152 $classes = 'wpnt-loading wpn-read';
153 $wp_admin_bar->add_menu( array(
154 'id' => 'notes',
155 'title' => '<span id="wpnt-notes-unread-count" class="' . esc_attr( $classes ) . '">
156 <span class="noticon noticon-notification"></span>
157 </span>',
158 'meta' => array(
159 '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>',
160 'class' => 'menupop',
161 ),
162 'parent' => 'top-secondary',
163 ) );
164 }
165
166 function print_js() {
167 $link_accounts_url = is_user_logged_in() && !Jetpack::is_user_connected() ? Jetpack::admin_url() : false;
168 ?>
169 <script type="text/javascript">
170 /* <![CDATA[ */
171 var wpNotesIsJetpackClient = true;
172 <?php if ( $link_accounts_url ) : ?>
173 var wpNotesLinkAccountsURL = '<?php print $link_accounts_url; ?>';
174 <?php endif; ?>
175 /* ]]> */
176 </script>
177 <?php
178 }
179
180 }
181
182 Jetpack_Notifications::init();
183