PluginProbe ʕ •ᴥ•ʔ
MainWP Child Reports / 2.0
MainWP Child Reports v2.0
0.0.1 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9.1 1.9.2 1.9.3 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1 2.1.1 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.3 2.3.1 trunk
mainwp-child-reports / classes / class-plugin.php
mainwp-child-reports / classes Last commit date
class-admin.php 6 years ago class-alert-trigger.php 6 years ago class-alert-type.php 6 years ago class-alert.php 6 years ago class-alerts-list.php 6 years ago class-alerts.php 6 years ago class-author.php 6 years ago class-cli.php 6 years ago class-connector.php 6 years ago class-connectors.php 6 years ago class-date-interval.php 6 years ago class-db-driver-wpdb.php 6 years ago class-db-driver.php 6 years ago class-db.php 6 years ago class-export.php 6 years ago class-exporter.php 6 years ago class-filter-input.php 6 years ago class-form-generator.php 6 years ago class-install.php 6 years ago class-list-table.php 6 years ago class-live-update.php 6 years ago class-log.php 6 years ago class-mainwp-child-report-helper.php 6 years ago class-network.php 6 years ago class-plugin.php 6 years ago class-preview-list-table.php 6 years ago class-query.php 6 years ago class-record.php 6 years ago class-settings.php 6 years ago class-uninstall.php 6 years ago debug.log 6 years ago
class-plugin.php
258 lines
1 <?php
2 namespace WP_MainWP_Stream;
3
4 class Plugin {
5 /**
6 * Plugin version number
7 *
8 * @const string
9 */
10 const VERSION = '3.5';
11
12 /**
13 * WP-CLI command
14 *
15 * @const string
16 */
17 const WP_CLI_COMMAND = 'mainwp_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 /**
68 * @var Child_Helper
69 */
70 public $child_helper;
71
72 /**
73 * Class constructor
74 */
75 public function __construct() {
76 $locate = $this->locate_plugin();
77
78 $this->locations = array(
79 'plugin' => $locate['plugin_basename'],
80 'dir' => $locate['dir_path'],
81 'url' => $locate['dir_url'],
82 'inc_dir' => $locate['dir_path'] . 'includes/',
83 'class_dir' => $locate['dir_path'] . 'classes/',
84 );
85
86 spl_autoload_register( array( $this, 'autoload' ) );
87
88 // Load helper functions
89 require_once $this->locations['inc_dir'] . 'functions.php';
90
91 // Load DB helper interface/class
92 $driver_class = apply_filters( 'wp_mainwp_stream_db_driver', '\WP_MainWP_Stream\DB_Driver_WPDB' );
93 $driver = null;
94
95 if ( class_exists( $driver_class ) ) {
96 $driver = new $driver_class();
97 $this->db = new DB( $driver );
98 }
99
100 $error = false;
101 if ( ! $this->db ) {
102 $error = esc_html__( 'Stream: Could not load chosen DB driver.', 'mainwp-child-reports' );
103 } elseif ( ! $driver instanceof DB_Driver ) {
104 $error = esc_html__( 'Stream: DB driver must implement DB Driver interface.', 'mainwp-child-reports' );
105 }
106
107 if ( $error ) {
108 wp_die(
109 esc_html( $error ),
110 esc_html__( 'Reports DB Error', 'mainwp-child-reports' )
111 );
112 }
113
114 // Load languages
115 add_action( 'plugins_loaded', array( $this, 'i18n' ) );
116
117 // Load logger class
118 $this->log = apply_filters( 'wp_mainwp_stream_log_handler', new Log( $this ) );
119
120 // Load settings and connectors after widgets_init and before the default init priority
121 add_action( 'init', array( $this, 'init' ), 9 );
122
123 // Add frontend indicator
124 add_action( 'wp_head', array( $this, 'frontend_indicator' ) );
125
126 // Change DB driver after plugin loaded if any add-ons want to replace
127 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 20 );
128
129 // Load admin area classes
130 if ( is_admin() || ( defined( 'WP_MAINWP_STREAM_DEV_DEBUG' ) && WP_MAINWP_STREAM_DEV_DEBUG ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
131 $this->admin = new Admin( $this );
132 $this->install = $driver->setup_storage( $this );
133 } elseif ( defined( 'DOING_CRON' ) && DOING_CRON ) {
134 $this->admin = new Admin( $this, $driver );
135 }
136 $this->child_helper = new MainWP_Child_Report_Helper( $this );
137
138 // Load WP-CLI command
139 if ( defined( 'WP_CLI' ) && WP_CLI ) {
140 \WP_CLI::add_command( self::WP_CLI_COMMAND, 'WP_MainWP_Stream\CLI' );
141 }
142 }
143
144 /**
145 * Autoloader for classes
146 *
147 * @param string $class
148 */
149 public function autoload( $class ) {
150 if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
151 return;
152 }
153
154 static $reflection;
155
156 if ( empty( $reflection ) ) {
157 $reflection = new \ReflectionObject( $this );
158 }
159
160 if ( $reflection->getNamespaceName() !== $matches['namespace'] ) {
161 return;
162 }
163
164 $autoload_name = $matches['autoload'];
165 $autoload_dir = \trailingslashit( $this->locations['class_dir'] );
166 $autoload_path = sprintf( '%sclass-%s.php', $autoload_dir, strtolower( str_replace( '_', '-', $autoload_name ) ) );
167
168 if ( is_readable( $autoload_path ) ) {
169 require_once $autoload_path;
170 }
171 }
172
173 /**
174 * Loads the translation files.
175 *
176 * @action plugins_loaded
177 */
178 public function i18n() {
179 load_plugin_textdomain( 'mainwp-child-reports', false, dirname( $this->locations['plugin'] ) . '/languages/' );
180 }
181
182 /*
183 * Load Settings, Notifications, and Connectors
184 *
185 * @action init
186 */
187 public function init() {
188 $this->settings = new Settings( $this );
189 $this->connectors = new Connectors( $this );
190 $this->alerts = new Alerts( $this );
191 $this->alerts_list = new Alerts_List( $this );
192
193 }
194
195 /**
196 * Displays an HTML comment in the frontend head to indicate that Stream is activated,
197 * and which version of Stream is currently in use.
198 *
199 * @action wp_head
200 *
201 * @return string|void An HTML comment, or nothing if the value is filtered out.
202 */
203 public function frontend_indicator() {
204 $comment = sprintf( 'Reports WordPress user activity plugin v%s', esc_html( $this->get_version() ) ); // Localization not needed
205
206 /**
207 * Filter allows the HTML output of the frontend indicator comment
208 * to be altered or removed, if desired.
209 *
210 * @return string The content of the HTML comment
211 */
212 $comment = apply_filters( 'wp_mainwp_stream_frontend_indicator', $comment );
213
214 if ( ! empty( $comment ) ) {
215 echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok
216 }
217 }
218
219 /**
220 * Version of plugin_dir_url() which works for plugins installed in the plugins directory,
221 * and for plugins bundled with themes.
222 *
223 * @throws \Exception
224 *
225 * @return array
226 */
227 private function locate_plugin() {
228 $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) );
229 $dir_path = plugin_dir_path( dirname( __FILE__ ) );
230 $dir_basename = basename( $dir_path );
231 $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php';
232
233 return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' );
234 }
235
236 /**
237 * Getter for the version number.
238 *
239 * @return string
240 */
241 public function get_version() {
242 return self::VERSION;
243 }
244
245 /**
246 * Change plugin database driver in case driver plugin loaded after stream
247 */
248 public function plugins_loaded() {
249 // Load DB helper interface/class
250 $driver_class = apply_filters( 'wp_mainwp_stream_db_driver', '\WP_MainWP_Stream\DB_Driver_WPDB' );
251
252 if ( class_exists( $driver_class ) ) {
253 $driver = new $driver_class();
254 $this->db = new DB( $driver );
255 }
256 }
257 }
258