PluginProbe
Stream – Activity Log & Audit Trail / 3.0.6
Stream – Activity Log & Audit Trail v3.0.6
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.0.6, at classes/class-plugin.php

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