PluginProbe
Stream – Activity Log & Audit Trail / 3.1.1
Stream – Activity Log & Audit Trail v3.1.1
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 / classes / class-plugin.php

class-plugin.php in Stream – Activity Log & Audit Trail 3.1.1, at classes/class-plugin.php

225 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WP_Stream;
3
4 class Plugin {
5 /**
6 * Plugin version number
7 *
8 * @const string
9 */
10 const VERSION = '3.1.1';
11
12 /**
13 * WP-CLI command
14 *
15 * @const string
16 */
17 const WP_CLI_COMMAND = 'stream';
18
19 /**
20 * @var Admin
21 */
22 public $admin;
23
24 /**
25 * @var Alerts
26 */
27 public $alerts;
28
29 /**
30 * @var Alerts_List
31 */
32 public $alerts_list;
33
34 /**
35 * @var Connectors
36 */
37 public $connectors;
38
39 /**
40 * @var DB
41 */
42 public $db;
43
44 /**
45 * @var Log
46 */
47 public $log;
48
49 /**
50 * @var Settings
51 */
52 public $settings;
53
54 /**
55 * @var Install
56 */
57 public $install;
58
59 /**
60 * URLs and Paths used by the plugin
61 *
62 * @var array
63 */
64 public $locations = array();
65
66 /**
67 * Class constructor
68 */
69 public function __construct() {
70 $locate = $this->locate_plugin();
71
72 $this->locations = array(
73 'plugin' => $locate['plugin_basename'],
74 'dir' => $locate['dir_path'],
75 'url' => $locate['dir_url'],
76 'inc_dir' => $locate['dir_path'] . 'includes/',
77 'class_dir' => $locate['dir_path'] . 'classes/',
78 );
79
80 spl_autoload_register( array( $this, 'autoload' ) );
81
82 // Load helper functions
83 require_once $this->locations['inc_dir'] . 'functions.php';
84
85 // Load DB helper interface/class
86 $driver = '\WP_Stream\DB';
87 if ( class_exists( $driver ) ) {
88 $this->db = new DB( $this );
89 }
90
91 if ( ! $this->db ) {
92 wp_die(
93 esc_html__( 'Stream: Could not load chosen DB driver.', 'stream' ),
94 esc_html__( 'Stream DB Error', 'stream' )
95 );
96 }
97
98 // Load languages
99 add_action( 'plugins_loaded', array( $this, 'i18n' ) );
100
101 // Load logger class
102 $this->log = apply_filters( 'wp_stream_log_handler', new Log( $this ) );
103
104 // Load settings and connectors after widgets_init and before the default init priority
105 add_action( 'init', array( $this, 'init' ), 9 );
106
107 // Add frontend indicator
108 add_action( 'wp_head', array( $this, 'frontend_indicator' ) );
109
110 // Load admin area classes
111 if ( is_admin() || ( defined( 'WP_STREAM_DEV_DEBUG' ) && WP_STREAM_DEV_DEBUG ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
112 $this->admin = new Admin( $this );
113 $this->install = new Install( $this );
114 } elseif ( defined( 'DOING_CRON' ) && DOING_CRON ) {
115 $this->admin = new Admin( $this );
116 }
117
118 // Load WP-CLI command
119 if ( defined( 'WP_CLI' ) && WP_CLI ) {
120 \WP_CLI::add_command( self::WP_CLI_COMMAND, 'WP_Stream\CLI' );
121 }
122 }
123
124 /**
125 * Autoloader for classes
126 *
127 * @param string $class
128 */
129 function autoload( $class ) {
130 if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
131 return;
132 }
133
134 static $reflection;
135
136 if ( empty( $reflection ) ) {
137 $reflection = new \ReflectionObject( $this );
138 }
139
140 if ( $reflection->getNamespaceName() !== $matches['namespace'] ) {
141 return;
142 }
143
144 $autoload_name = $matches['autoload'];
145 $autoload_dir = \trailingslashit( $this->locations['class_dir'] );
146 $autoload_path = sprintf( '%sclass-%s.php', $autoload_dir, strtolower( str_replace( '_', '-', $autoload_name ) ) );
147
148 if ( is_readable( $autoload_path ) ) {
149 require_once $autoload_path;
150 }
151 }
152
153 /**
154 * Loads the translation files.
155 *
156 * @action plugins_loaded
157 */
158 public function i18n() {
159 load_plugin_textdomain( 'stream', false, dirname( $this->locations['plugin'] ) . '/languages/' );
160 }
161
162 /*
163 * Load Settings, Notifications, and Connectors
164 *
165 * @action init
166 */
167 public function init() {
168 $this->settings = new Settings( $this );
169 $this->connectors = new Connectors( $this );
170 $this->alerts = new Alerts( $this );
171 $this->alerts_list = new Alerts_List( $this );
172
173 }
174
175 /**
176 * Displays an HTML comment in the frontend head to indicate that Stream is activated,
177 * and which version of Stream is currently in use.
178 *
179 * @action wp_head
180 *
181 * @return string|void An HTML comment, or nothing if the value is filtered out.
182 */
183 public function frontend_indicator() {
184 $comment = sprintf( 'Stream WordPress user activity plugin v%s', esc_html( $this->get_version() ) ); // Localization not needed
185
186 /**
187 * Filter allows the HTML output of the frontend indicator comment
188 * to be altered or removed, if desired.
189 *
190 * @return string The content of the HTML comment
191 */
192 $comment = apply_filters( 'wp_stream_frontend_indicator', $comment );
193
194 if ( ! empty( $comment ) ) {
195 echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok
196 }
197 }
198
199 /**
200 * Version of plugin_dir_url() which works for plugins installed in the plugins directory,
201 * and for plugins bundled with themes.
202 *
203 * @throws \Exception
204 *
205 * @return array
206 */
207 private function locate_plugin() {
208 $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) );
209 $dir_path = plugin_dir_path( dirname( __FILE__ ) );
210 $dir_basename = basename( $dir_path );
211 $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php';
212
213 return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' );
214 }
215
216 /**
217 * Getter for the version number.
218 *
219 * @return string
220 */
221 public function get_version() {
222 return self::VERSION;
223 }
224 }
225