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

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