-
Notifications
You must be signed in to change notification settings - Fork 116
/
stream.php
executable file
·327 lines (278 loc) · 9.44 KB
/
stream.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
/**
* Plugin Name: Stream
* Plugin URI: https://wp-stream.com/
* Description: Stream tracks logged-in user activity so you can monitor every change made on your WordPress site in beautifully organized detail. All activity is organized by context, action and IP address for easy filtering. Developers can extend Stream with custom connectors to log any kind of action.
* Version: 1.4.5
* Author: X-Team
* Author URI: https://wp-stream.com/
* License: GPLv2+
* Text Domain: stream
* Domain Path: /languages
*/
/**
* Copyright (c) 2014 X-Team (http://x-team.com/)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class WP_Stream {
/**
* Plugin version number
*
* @const string
*/
const VERSION = '1.4.5';
/**
* Hold Stream instance
*
* @var string
*/
public static $instance;
/**
* @var WP_Stream_DB
*/
public $db = null;
/**
* @var WP_Stream_Network
*/
public $network = null;
/**
* Class constructor
*/
private function __construct() {
define( 'WP_STREAM_PLUGIN', plugin_basename( __FILE__ ) );
define( 'WP_STREAM_DIR', plugin_dir_path( __FILE__ ) );
define( 'WP_STREAM_URL', plugin_dir_url( __FILE__ ) );
define( 'WP_STREAM_INC_DIR', WP_STREAM_DIR . 'includes/' );
// Load filters polyfill
require_once WP_STREAM_INC_DIR . 'filter-input.php';
// Load DB helper class
require_once WP_STREAM_INC_DIR . 'db.php';
$this->db = new WP_Stream_DB;
// Check DB and add message if not present
add_action( 'init', array( $this, 'verify_database_present' ) );
// Load languages
add_action( 'plugins_loaded', array( __CLASS__, 'i18n' ) );
// Load settings, enabling extensions to hook in
require_once WP_STREAM_INC_DIR . 'settings.php';
add_action( 'init', array( 'WP_Stream_Settings', 'load' ) );
// Load network class
if ( is_multisite() ) {
require_once WP_STREAM_INC_DIR . 'network.php';
$this->network = new WP_Stream_Network;
}
// Load logger class
require_once WP_STREAM_INC_DIR . 'log.php';
add_action( 'plugins_loaded', array( 'WP_Stream_Log', 'load' ) );
// Load connectors
require_once WP_STREAM_INC_DIR . 'connectors.php';
add_action( 'init', array( 'WP_Stream_Connectors', 'load' ), 0 );
// Load query class
require_once WP_STREAM_INC_DIR . 'query.php';
require_once WP_STREAM_INC_DIR . 'context-query.php';
// Load support for feeds
require_once WP_STREAM_INC_DIR . 'feeds.php';
add_action( 'init', array( 'WP_Stream_Feeds', 'load' ) );
// Add frontend indicator
add_action( 'wp_head', array( $this, 'frontend_indicator' ) );
// Include Stream extension updater
require_once WP_STREAM_INC_DIR . 'updater.php';
WP_Stream_Updater::instance();
if ( is_admin() ) {
require_once WP_STREAM_INC_DIR . 'admin.php';
require_once WP_STREAM_INC_DIR . 'extensions.php';
add_action( 'plugins_loaded', array( 'WP_Stream_Admin', 'load' ) );
add_action( 'admin_init', array( 'WP_Stream_Extensions', 'get_instance' ) );
add_action( 'init', array( __CLASS__, 'install' ), 10, 1 );
// Registers a hook that connectors and other plugins can use whenever a stream update happens
add_action( 'admin_init', array( __CLASS__, 'update_activation_hook' ) );
require_once WP_STREAM_INC_DIR . 'dashboard.php';
add_action( 'plugins_loaded', array( 'WP_Stream_Dashboard_Widget', 'load' ) );
require_once WP_STREAM_INC_DIR . 'live-update.php';
add_action( 'plugins_loaded', array( 'WP_Stream_Live_Update', 'load' ) );
require_once WP_STREAM_INC_DIR . 'pointers.php';
add_action( 'plugins_loaded', array( 'WP_Stream_Pointers', 'load' ) );
}
// Load deprecated functions
require_once WP_STREAM_INC_DIR . 'deprecated.php';
}
/**
* Invoked when the PHP version check fails. Load up the translations and
* add the error message to the admin notices
*/
static function fail_php_version() {
add_action( 'plugins_loaded', array( __CLASS__, 'i18n' ) );
self::notice( __( 'Stream requires PHP version 5.3+, plugin is currently NOT ACTIVE.', 'stream' ) );
}
/**
* Loads the translation files.
*
* @access public
* @action plugins_loaded
* @return void
*/
public static function i18n() {
load_plugin_textdomain( 'stream', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Installation / Upgrade checks
*
* @action register_activation_hook
* @return void
*/
public static function install() {
/**
* Filter will halt install() if set to true
*
* @param bool
* @return bool
*/
if ( apply_filters( 'wp_stream_no_tables', false ) ) {
return;
}
// Install plugin tables
require_once WP_STREAM_INC_DIR . 'install.php';
$update = WP_Stream_Install::get_instance();
}
/**
* Verify that all needed databases are present and add an error message if not.
*
* @return void
*/
public function verify_database_present() {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
/**
* Filter will halt verify_database_present() if set to true
*
* @param bool
* @return bool
*/
if ( apply_filters( 'wp_stream_no_tables', false ) ) {
return;
}
global $wpdb;
$database_message = '';
$uninstall_message = '';
// Check if all needed DB is present
$missing_tables = array();
foreach ( $this->db->get_table_names() as $table_name ) {
if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) !== $table_name ) {
$missing_tables[] = $table_name;
}
}
if ( $missing_tables ) {
$database_message .= sprintf(
'%s <strong>%s</strong>',
_n(
'The following table is not present in the WordPress database:',
'The following tables are not present in the WordPress database:',
count( $missing_tables ),
'stream'
),
esc_html( implode( ', ', $missing_tables ) )
);
}
if ( is_plugin_active_for_network( WP_STREAM_PLUGIN ) && current_user_can( 'manage_network_plugins' ) ) {
$uninstall_message = sprintf( __( 'Please <a href="%s">uninstall</a> the Stream plugin and activate it again.', 'stream' ), network_admin_url( 'plugins.php#stream' ) );
} elseif ( current_user_can( 'activate_plugins' ) ) {
$uninstall_message = sprintf( __( 'Please <a href="%s">uninstall</a> the Stream plugin and activate it again.', 'stream' ), admin_url( 'plugins.php#stream' ) );
}
// Check upgrade routine
self::install();
if ( ! empty( $database_message ) ) {
self::notice( $database_message );
if ( ! empty( $uninstall_message ) ) {
self::notice( $uninstall_message );
}
}
}
static function update_activation_hook() {
WP_Stream_Admin::register_update_hook( dirname( plugin_basename( __FILE__ ) ), array( __CLASS__, 'install' ), self::VERSION );
}
/**
* Whether the current PHP version meets the minimum requirements
*
* @return bool
*/
public static function is_valid_php_version() {
return version_compare( PHP_VERSION, '5.3', '>=' );
}
/**
* Show an error or other message, using admin_notice or WP-CLI logger
*
* @param string $message
* @param bool $is_error
* @return void
*/
public static function notice( $message, $is_error = true ) {
if ( defined( 'WP_CLI' ) ) {
$message = strip_tags( $message );
if ( $is_error ) {
WP_CLI::warning( $message );
} else {
WP_CLI::success( $message );
}
} else {
$print_message = function () use ( $message, $is_error ) {
$class_name = ( $is_error ? 'error' : 'updated' );
$html_message = sprintf( '<div class="%s">%s</div>', $class_name, wpautop( $message ) );
echo wp_kses_post( $html_message );
};
add_action( 'all_admin_notices', $print_message );
}
}
/**
* Displays an HTML comment in the frontend head to indicate that Stream is activated,
* and which version of Stream is currently in use.
*
* @since 1.4.5
*
* @action wp_head
* @return string|void An HTML comment, or nothing if the value is filtered out.
*/
public function frontend_indicator() {
$comment = sprintf( 'Stream WordPress user activity plugin v%s', esc_html( self::VERSION ) ); // Localization not needed
/**
* Filter allows the HTML output of the frontend indicator comment
* to be altered or removed, if desired.
*
* @return string $comment The content of the HTML comment
*/
$comment = apply_filters( 'wp_stream_frontend_indicator', $comment );
if ( ! empty( $comment ) ) {
echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok
}
}
/**
* Return active instance of WP_Stream, create one if it doesn't exist
*
* @return WP_Stream
*/
public static function get_instance() {
if ( empty( self::$instance ) ) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
}
if ( WP_Stream::is_valid_php_version() ) {
$GLOBALS['wp_stream'] = WP_Stream::get_instance();
register_activation_hook( __FILE__, array( 'WP_Stream', 'install' ) );
} else {
WP_Stream::fail_php_version();
}