PluginProbe
Stream – Activity Log & Audit Trail / 2.0.2
Stream – Activity Log & Audit Trail v2.0.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
stream / stream.php

stream.php in Stream – Activity Log & Audit Trail 2.0.2, at stream.php

389 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Stream
4 * Plugin URI: https://wp-stream.com/
5 * 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.
6 * Version: 2.0.2
7 * Author: Stream
8 * Author URI: https://wp-stream.com/
9 * License: GPLv2+
10 * Text Domain: stream
11 * Domain Path: /languages
12 */
13
14 /**
15 * Copyright (c) 2014 WP Stream Pty Ltd (https://wp-stream.com/)
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License, version 2 or, at
19 * your discretion, any later version, as published by the Free
20 * Software Foundation.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */
31
32 class WP_Stream {
33
34 /**
35 * Plugin version number
36 *
37 * @const string
38 */
39 const VERSION = '2.0.2';
40
41 /**
42 * Hold Stream instance
43 *
44 * @var string
45 */
46 public static $instance;
47
48 /**
49 * @var WP_Stream_DB_Base
50 */
51 public static $db;
52
53 /**
54 * @var WP_Stream_API
55 */
56 public static $api;
57
58 /**
59 * Admin notices, collected and displayed on proper action
60 *
61 * @var array
62 */
63 public static $notices = array();
64
65 /**
66 * An array of deprecated extension plugin class/dir pairs
67 *
68 * @var array
69 */
70 public static $deprecated_extensions = array(
71 'WP_Stream_Cherry_Pick' => 'stream-cherry-pick/stream-cherry-pick.php',
72 'WP_Stream_Data_Exporter' => 'stream-data-exporter/stream-data-exporter.php',
73 'WP_Stream_Notifications' => 'stream-notifications/stream-notifications.php',
74 'WP_Stream_Reports' => 'stream-reports/stream-reports.php',
75 );
76
77 /**
78 * Class constructor
79 */
80 private function __construct() {
81 define( 'WP_STREAM_PLUGIN', plugin_basename( __FILE__ ) );
82 define( 'WP_STREAM_DIR', plugin_dir_path( __FILE__ ) );
83 define( 'WP_STREAM_URL', plugin_dir_url( __FILE__ ) );
84 define( 'WP_STREAM_INC_DIR', WP_STREAM_DIR . 'includes/' );
85 define( 'WP_STREAM_CLASS_DIR', WP_STREAM_DIR . 'classes/' );
86 define( 'WP_STREAM_EXTENSIONS_DIR', WP_STREAM_DIR . 'extensions/' );
87
88 spl_autoload_register( array( $this, 'autoload' ) );
89
90 // Load helper functions
91 require_once WP_STREAM_INC_DIR . 'functions.php';
92
93 // Load DB helper interface/class
94 $driver = 'WP_Stream_DB';
95 if ( class_exists( $driver ) ) {
96 self::$db = new $driver;
97 }
98
99 if ( ! self::$db ) {
100 wp_die( __( 'Stream: Could not load chosen DB driver.', 'stream' ), 'Stream DB Error' );
101 }
102
103 /**
104 * Filter allows a custom Stream API class to be instantiated
105 *
106 * @return object The API class object
107 */
108 self::$api = apply_filters( 'wp_stream_api_class', new WP_Stream_API );
109
110 // Install the plugin
111 add_action( 'wp_stream_before_db_notices', array( __CLASS__, 'install' ) );
112
113 // Load languages
114 add_action( 'plugins_loaded', array( __CLASS__, 'i18n' ) );
115
116 // Load settings, enabling extensions to hook in
117 add_action( 'init', array( 'WP_Stream_Settings', 'load' ), 9 );
118
119 // Load logger class
120 add_action( 'plugins_loaded', array( 'WP_Stream_Log', 'load' ) );
121
122 // Load connectors after widgets_init, but before the default of 10
123 add_action( 'init', array( 'WP_Stream_Connectors', 'load' ), 9 );
124
125 // Load extensions
126 foreach ( glob( WP_STREAM_EXTENSIONS_DIR . '*' ) as $extension ) {
127 require_once sprintf( '%s/class-wp-stream-%s.php', $extension, basename( $extension ) );
128 }
129
130 // Load support for feeds
131 add_action( 'init', array( 'WP_Stream_Feeds', 'load' ) );
132
133 // Add frontend indicator
134 add_action( 'wp_head', array( $this, 'frontend_indicator' ) );
135
136 if ( is_admin() ) {
137 add_action( 'plugins_loaded', array( 'WP_Stream_Admin', 'load' ) );
138
139 add_action( 'plugins_loaded', array( 'WP_Stream_Dashboard_Widget', 'load' ) );
140
141 add_action( 'plugins_loaded', array( 'WP_Stream_Live_Update', 'load' ) );
142
143 add_action( 'plugins_loaded', array( 'WP_Stream_Pointers', 'load' ) );
144
145 add_action( 'plugins_loaded', array( 'WP_Stream_Migrate', 'load' ) );
146 }
147 }
148
149 /**
150 * Invoked when the PHP version check fails. Load up the translations and
151 * add the error message to the admin notices
152 */
153 public static function fail_php_version() {
154 add_action( 'plugins_loaded', array( __CLASS__, 'i18n' ) );
155 self::notice( __( 'Stream requires PHP version 5.3+, plugin is currently NOT ACTIVE.', 'stream' ) );
156 }
157
158 /**
159 *
160 */
161 public static function deprecated_plugins_exist() {
162 foreach ( self::$deprecated_extensions as $class => $dir ) {
163 if ( class_exists( $class ) ) {
164 return true;
165 }
166 }
167
168 return false;
169 }
170
171 /**
172 *
173 */
174 public static function deprecated_plugins_notice() {
175 add_action( 'plugins_loaded', array( __CLASS__, 'i18n' ) );
176
177 if ( ! function_exists( 'get_plugins' ) ) {
178 require_once ABSPATH . 'wp-admin/includes/plugin.php';
179 }
180
181 $message = null;
182
183 foreach ( self::$deprecated_extensions as $class => $dir ) {
184 if ( class_exists( $class ) ) {
185 $data = get_plugin_data( sprintf( '%s/%s', WP_PLUGIN_DIR, $dir ) );
186 $name = isset( $data['Name'] ) ? $data['Name'] : $dir;
187 $message .= sprintf( '<li><strong>%s</strong></li>', esc_html( $name ) );
188
189 deactivate_plugins( $dir );
190 }
191 }
192
193 if ( ! empty( $message ) ) {
194 ob_start();
195 ?>
196 <h3><?php _e( 'Deprecated Plugins Found', 'stream' ) ?></h3>
197 <p><?php _e( 'The following plugins are deprecated and will be deactivated in order to activate', 'stream' ) ?> <strong>Stream <?php echo esc_html( self::VERSION ) ?></strong>:</p>
198 <ul>
199 <?php
200 $start = ob_get_clean();
201
202 ob_start();
203 ?>
204 </ul>
205 <p>
206 <a href='#' onclick="location.reload(true); return false;" class="button button-large"><?php _e( 'Continue', 'stream' ) ?></a>
207 </p>
208 <?php
209 $end = ob_get_clean();
210
211 wp_die( $start . $message . $end, __( 'Deprecated Plugins Found', 'stream' ) );
212 }
213 }
214
215 /**
216 * Autoloader for classes
217 *
218 * @param string $class
219 * @return void
220 */
221 function autoload( $class ) {
222 $class = strtolower( str_replace( '_', '-', $class ) );
223 $class_file = sprintf( '%sclass-%s.php', WP_STREAM_CLASS_DIR, $class );
224
225 if ( is_readable( $class_file ) ) {
226 require_once $class_file;
227 }
228 }
229
230 /**
231 * Loads the translation files.
232 *
233 * @access public
234 * @action plugins_loaded
235 * @return void
236 */
237 public static function i18n() {
238 load_plugin_textdomain( 'stream', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
239 }
240
241 /**
242 * Whether the current PHP version meets the minimum requirements
243 *
244 * @return bool
245 */
246 public static function is_valid_php_version() {
247 return version_compare( PHP_VERSION, '5.3', '>=' );
248 }
249
250 /**
251 * Is Stream connected?
252 *
253 * @return bool
254 */
255 public static function is_connected() {
256 return ( self::$api->api_key && self::$api->site_uuid );
257 }
258
259 /**
260 * Is Stream in development mode?
261 *
262 * @return bool
263 */
264 public static function is_development_mode() {
265 $development_mode = false;
266
267 if ( defined( 'WP_STREAM_DEV_DEBUG' ) ) {
268 $development_mode = WP_STREAM_DEV_DEBUG;
269 } else if ( site_url() && false === strpos( site_url(), '.' ) ) {
270 $development_mode = true;
271 }
272
273 /**
274 * Filter allows development mode to be overridden
275 *
276 * @return bool
277 */
278 return apply_filters( 'wp_stream_development_mode', $development_mode );
279 }
280
281 /**
282 * Handle notice messages according to the appropriate context (WP-CLI or the WP Admin)
283 *
284 * @param string $message
285 * @param bool $is_error
286 * @return void
287 */
288 public static function notice( $message, $is_error = true ) {
289 if ( defined( 'WP_CLI' ) ) {
290 $message = strip_tags( $message );
291 if ( $is_error ) {
292 WP_CLI::warning( $message );
293 } else {
294 WP_CLI::success( $message );
295 }
296 } else {
297 // Trigger admin notices late, so that any notices which occur during page load are displayed
298 add_action( 'shutdown', array( __CLASS__, 'admin_notices' ) );
299
300 $notice = compact( 'message', 'is_error' );
301
302 if ( ! in_array( $notice, self::$notices ) ) {
303 self::$notices[] = $notice;
304 }
305 }
306 }
307
308 /**
309 * Show an error or other message in the WP Admin
310 *
311 * @action shutdown
312 * @return void
313 */
314 public static function admin_notices() {
315 global $allowedposttags;
316
317 $custom = array(
318 'progress' => array(
319 'class' => true,
320 'id' => true,
321 'max' => true,
322 'style' => true,
323 'value' => true,
324 ),
325 );
326
327 $allowed_html = array_merge( $allowedposttags, $custom );
328
329 ksort( $allowed_html );
330
331 foreach ( self::$notices as $notice ) {
332 $class_name = empty( $notice['is_error'] ) ? 'updated' : 'error';
333 $html_message = sprintf( '<div class="%s">%s</div>', esc_attr( $class_name ), wpautop( $notice['message'] ) );
334
335 echo wp_kses( $html_message, $allowed_html );
336 }
337 }
338
339 /**
340 * Displays an HTML comment in the frontend head to indicate that Stream is activated,
341 * and which version of Stream is currently in use.
342 *
343 * @since 1.4.5
344 *
345 * @action wp_head
346 * @return string|void An HTML comment, or nothing if the value is filtered out.
347 */
348 public function frontend_indicator() {
349 $comment = sprintf( 'Stream WordPress user activity plugin v%s', esc_html( self::VERSION ) ); // Localization not needed
350
351 /**
352 * Filter allows the HTML output of the frontend indicator comment
353 * to be altered or removed, if desired.
354 *
355 * @return string The content of the HTML comment
356 */
357 $comment = apply_filters( 'wp_stream_frontend_indicator', $comment );
358
359 if ( ! empty( $comment ) ) {
360 echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok
361 }
362 }
363
364 /**
365 * Return active instance of WP_Stream, create one if it doesn't exist
366 *
367 * @return WP_Stream
368 */
369 public static function get_instance() {
370 if ( empty( self::$instance ) ) {
371 $class = __CLASS__;
372 self::$instance = new $class;
373 }
374
375 return self::$instance;
376 }
377
378 }
379
380 if ( ! WP_Stream::is_valid_php_version() ) {
381 WP_Stream::fail_php_version();
382 } elseif ( WP_Stream::deprecated_plugins_exist() ) {
383 WP_Stream::deprecated_plugins_notice();
384 } else {
385 $GLOBALS['wp_stream'] = WP_Stream::get_instance();
386 }
387
388 register_deactivation_hook( __FILE__, array( 'WP_Stream_Admin', 'remove_api_authentication' ) );
389