PluginProbe
Sessions / 2.13.1
Sessions v2.13.1
2.1.0 2.10.0 2.11.0 2.12.0 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.2.0 2.3.0 2.3.1 2.4.0 2.4.1 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.1.0 3.1.1 All 39 releases
sessions / includes / plugin / class-core.php

class-core.php in Sessions 2.13.1, at includes/plugin/class-core.php

279 lines 14.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file that defines the core plugin class
4 *
5 * A class definition that includes attributes and functions used across both the
6 * public-facing side of the site and the admin area.
7 *
8 * @package Plugin
9 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
10 * @since 1.0.0
11 */
12
13 namespace POSessions\Plugin;
14
15 use POSessions\System\Environment;
16 use POSessions\System\Loader;
17 use POSessions\System\I18n;
18 use POSessions\System\Assets;
19 use POSessions\Library\Libraries;
20 use POSessions\System\Cache;
21 use POSessions\System\Nag;
22 use POSessions\System\Session;
23 use POSessions\Plugin\Feature\Analytics;
24 use POSessions\System\Option;
25
26 /**
27 * The core plugin class.
28 *
29 * This is used to define internationalization, admin-specific hooks, and
30 * public-facing site hooks.
31 *
32 * @package Plugin
33 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
34 * @since 1.0.0
35 */
36 class Core {
37
38 /**
39 * The loader that's responsible for maintaining and registering all hooks that power
40 * the plugin.
41 *
42 * @since 1.0.0
43 * @access protected
44 * @var Loader $loader Maintains and registers all hooks for the plugin.
45 */
46 protected $loader;
47
48 /**
49 * Define the core functionality of the plugin.
50 *
51 * Load the dependencies, define the locale, and set the hooks for the admin area and
52 * the public-facing side of the site.
53 *
54 * @since 1.0.0
55 */
56 public function __construct() {
57 $this->loader = new Loader();
58 $this->define_global_hooks();
59 $this->define_admin_hooks();
60 $this->define_public_hooks();
61 $this->define_custom_messages();
62 if ( \DecaLog\Engine::isDecalogActivated() && Option::network_get( 'metrics' ) && Environment::exec_mode_for_metrics() && Option::network_get( 'analytics' ) ) {
63 $this->define_metrics();
64 }
65 }
66
67
68 /**
69 * Register all of the hooks related to the features of the plugin.
70 *
71 * @since 1.0.0
72 * @access private
73 */
74 private function define_global_hooks() {
75 $bootstrap = new Initializer();
76 $assets = new Assets();
77 $updater = new Updater();
78 $libraries = new Libraries();
79 $this->loader->add_action( 'init', 'POSessions\Plugin\Integration\Databeam', 'init' );
80 $this->loader->add_filter( 'perfopsone_plugin_info', self::class, 'perfopsone_plugin_info' );
81 $this->loader->add_action( 'init', $bootstrap, 'initialize' );
82 $this->loader->add_action( 'init', $bootstrap, 'late_initialize', PHP_INT_MAX );
83 $this->loader->add_action( 'wp_head', $assets, 'prefetch' );
84 add_shortcode( 'pose-changelog', [ $updater, 'sc_get_changelog' ] );
85 add_shortcode( 'pose-libraries', [ $libraries, 'sc_get_list' ] );
86 add_shortcode( 'pose-statistics', [ 'POSessions\System\Statistics', 'sc_get_raw' ] );
87 }
88
89 /**
90 * Register all of the hooks related to the admin area functionality
91 * of the plugin.
92 *
93 * @since 1.0.0
94 * @access private
95 */
96 private function define_admin_hooks() {
97 $plugin_admin = new Sessions_Admin();
98 $nag = new Nag();
99 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
100 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
101 $this->loader->add_action( 'admin_menu', $plugin_admin, 'init_admin_menus' );
102 $this->loader->add_action( 'admin_menu', $plugin_admin, 'finalize_admin_menus', 100 );
103 $this->loader->add_action( 'admin_menu', $plugin_admin, 'normalize_admin_menus', 110 );
104 $this->loader->add_action( 'admin_init', $plugin_admin, 'init_settings_sections' );
105 $this->loader->add_filter( 'plugin_action_links_' . plugin_basename( POSE_PLUGIN_DIR . POSE_SLUG . '.php' ), $plugin_admin, 'add_actions_links', 10, 4 );
106 $this->loader->add_filter( 'plugin_row_meta', $plugin_admin, 'add_row_meta', 10, 2 );
107 $this->loader->add_action( 'admin_notices', $nag, 'display' );
108 $this->loader->add_action( 'wp_ajax_hide_pose_nag', $nag, 'hide_callback' );
109 $this->loader->add_action( 'wp_ajax_pose_get_stats', 'POSessions\Plugin\Feature\AnalyticsFactory', 'get_stats_callback' );
110 }
111
112 /**
113 * Register all of the hooks related to the public-facing functionality
114 * of the plugin.
115 *
116 * @since 1.0.0
117 * @access private
118 */
119 private function define_public_hooks() {
120 $plugin_public = new Sessions_Public();
121 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
122 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
123 }
124
125 /**
126 * Register all of the filters related to messages customization.
127 *
128 * @since 1.0.0
129 * @access private
130 */
131 private function define_custom_messages() {
132 if ( '' !== Option::network_get( 'blocked_message' ) ) {
133 add_filter(
134 'sessions_blocked_message',
135 function( $message ) {
136 return Option::network_get( 'blocked_message' );
137 },
138 0,
139 1
140 );
141 }
142 if ( '' !== Option::network_get( 'bad_ip_message' ) ) {
143 add_filter(
144 'sessions_bad_ip_message',
145 function( $message ) {
146 return Option::network_get( 'bad_ip_message' );
147 },
148 0,
149 1
150 );
151 }
152 }
153
154 /**
155 * Register all metrics of the plugin.
156 *
157 * @since 1.2.0
158 * @access private
159 */
160 private function define_metrics() {
161 $span = \DecaLog\Engine::tracesLogger( POSE_SLUG )->startSpan( 'Metrics collation', DECALOG_SPAN_PLUGINS_LOAD );
162 $cache_id = 'metrics/lastcheck';
163 $analytics = Cache::get_global( $cache_id );
164 if ( ! isset( $analytics ) ) {
165 $analytics = Analytics::get_status_kpi_collection( [ 'site_id' => 0 ] );
166 Cache::set_global( $cache_id, $analytics, 'metrics' );
167 }
168 if ( isset( $analytics ) ) {
169 $metrics = \DecaLog\Engine::metricsLogger( POSE_SLUG );
170 if ( array_key_exists( 'data', $analytics ) ) {
171 foreach ( $analytics['data'] as $kpi ) {
172 $m = $kpi['metrics'] ?? null;
173 if ( isset( $m ) ) {
174 switch ( $m['type'] ) {
175 case 'gauge':
176 $metrics->createProdGauge( $m['name'], $m['value'], $m['desc'] );
177 break;
178 case 'counter':
179 $metrics->createProdCounter( $m['name'], $m['desc'] );
180 $metrics->incProdCounter( $m['name'], $m['value'] );
181 break;
182 }
183 }
184 }
185 }
186 }
187 \DecaLog\Engine::tracesLogger( POSE_SLUG )->endSpan( $span );
188 }
189
190 /**
191 * Run the loader to execute all of the hooks with WordPress.
192 *
193 * @since 1.0.0
194 */
195 public function run() {
196 $this->loader->run();
197 }
198
199 /**
200 * The reference to the class that orchestrates the hooks with the plugin.
201 *
202 * @since 1.0.0
203 * @return Loader Orchestrates the hooks of the plugin.
204 */
205 public function get_loader() {
206 return $this->loader;
207 }
208
209 /**
210 * Adds full plugin identification.
211 *
212 * @param array $plugin The already set identification information.
213 * @return array The extended identification information.
214 * @since 1.0.0
215 */
216 public static function perfopsone_plugin_info( $plugin ) {
217 $plugin[ POSE_SLUG ] = [
218 'name' => POSE_PRODUCT_NAME,
219 'code' => POSE_CODENAME,
220 'version' => POSE_VERSION,
221 'url' => POSE_PRODUCT_URL,
222 'icon' => self::get_base64_logo(),
223 ];
224 return $plugin;
225 }
226
227 /**
228 * Returns a base64 svg resource for the plugin logo.
229 *
230 * @return string The svg resource as a base64.
231 * @since 1.0.0
232 */
233 public static function get_base64_logo() {
234
235 $source = '<svg width="100%" height="100%" viewBox="0 0 1001 1001" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">';
236 $source .= '<g id="Sessions" transform="matrix(10.0067,0,0,10.0067,0,0)">';
237 $source .= '<rect x="0" y="0" width="100" height="100" style="fill:none;"/>';
238 $source .= '<g id="Windows" transform="matrix(2.01699,0,0,2.01699,-0.581152,-27.7051)">';
239 $source .= '<g transform="matrix(0,-39.9201,-39.9201,0,25,48.6977)">';
240 $source .= '<path d="M0.769,0.391C0.769,0.424 0.742,0.451 0.709,0.451L0.078,0.451C0.044,0.451 0.017,0.424 0.017,0.391L0.017,-0.391C0.017,-0.424 0.044,-0.451 0.078,-0.451L0.709,-0.451C0.742,-0.451 0.769,-0.424 0.769,-0.391L0.769,0.391Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/>';
241 $source .= '</g>';
242 $source .= '<g transform="matrix(0,-38.5844,-38.5844,0,25,29)">';
243 $source .= '<path d="M0.285,0.403C0.285,0.438 0.257,0.467 0.221,0.467L0.13,0.467L0.13,-0.467L0.221,-0.467C0.257,-0.467 0.285,-0.438 0.285,-0.403L0.285,0.403Z" style="fill:url(#_Linear2);fill-rule:nonzero;"/>';
244 $source .= '</g>';
245 $source .= '<g transform="matrix(0,-1,-1,0,10.3814,19.9044)">';
246 $source .= '<path d="M-1.017,-1.018C-1.579,-1.018 -2.036,-0.562 -2.036,0C-2.036,0.562 -1.579,1.017 -1.017,1.017C-0.455,1.017 0.001,0.562 0.001,0C0.001,-0.562 -0.455,-1.018 -1.017,-1.018" style="fill:white;fill-rule:nonzero;"/>';
247 $source .= '</g>';
248 $source .= '<g transform="matrix(0,-1,-1,0,14.4678,19.9039)">';
249 $source .= '<path d="M-1.018,-1.019C-1.58,-1.019 -2.037,-0.563 -2.037,0C-2.037,0.562 -1.58,1.018 -1.018,1.018C-0.456,1.018 0,0.562 0,0C0,-0.563 -0.456,-1.019 -1.018,-1.019" style="fill:white;fill-rule:nonzero;"/>';
250 $source .= '</g>';
251 $source .= '<g transform="matrix(0,-1,-1,0,18.5542,19.9039)">';
252 $source .= '<path d="M-1.018,-1.019C-1.58,-1.019 -2.037,-0.563 -2.037,-0.001C-2.037,0.562 -1.58,1.018 -1.018,1.018C-0.456,1.018 0,0.562 0,-0.001C0,-0.563 -0.456,-1.019 -1.018,-1.019" style="fill:white;fill-rule:nonzero;"/>';
253 $source .= '</g>';
254 $source .= '<g opacity="0.5">';
255 $source .= '<g transform="matrix(1,0,0,1,0,21)">';
256 $source .= '<rect x="10" y="5" width="30" height="19" style="fill:white;"/>';
257 $source .= '</g>';
258 $source .= '</g>';
259 $source .= '<g transform="matrix(1,0,0,1,35.4966,33)">';
260 $source .= '<path d="M0,6L-20.993,6C-22.375,6 -23.497,4.879 -23.497,3.497L-23.497,2.503C-23.497,1.121 -22.375,0 -20.993,0L0,0C1.382,0 2.503,1.121 2.503,2.503L2.503,3.497C2.503,4.879 1.382,6 0,6" style="fill:white;fill-rule:nonzero;"/>';
261 $source .= '</g>';
262 $source .= '</g>';
263 $source .= '<g id="Humans" transform="matrix(0.179833,0,0,0.183262,32.0785,32.4315)">';
264 $source .= '<path d="M90.258,170.26L91.519,169.08L92.786,170.26C103.868,180.694 116.154,186.447 127.326,186.447C139.062,186.447 151.183,181.343 162.379,171.699L163.316,170.906L165.775,172.104C167.859,174.004 171.597,176.731 173.284,177.553L175.59,178.676L175.338,178.928L176.22,179.456C178.337,180.705 180.595,181.919 183.171,183.21C185.765,184.356 187.999,185.228 190.377,186.008C190.833,186.17 201.888,189.737 214.498,195.585L216.75,196.27C228.724,200.833 233.791,207.265 233.972,207.488C252.563,235.074 255.691,295.326 255.992,302.063C255.854,311.478 253.181,313.928 252.468,314.39C210.806,333.041 147.858,337.887 135.677,338.656L135.344,338.675L134.99,338.584C134.582,338.452 134.158,338.393 133.642,338.393L133.636,338.393L133.207,338.411C129.88,338.645 127.118,338.754 124.548,338.754L122.53,338.754C114.943,338.297 47.071,333.854 3.635,314.53C2.755,314.158 0.179,311.191 0.002,302.551C0.008,301.908 2.245,236.864 21.752,207.885C22.704,206.685 28.018,200.511 38.616,196.452C47.939,193.594 70.991,185.943 83.601,176.816C84.132,176.492 84.661,175.952 85.219,175.387C86.133,174.38 88.051,172.319 90.258,170.26ZM220.082,186.53L218.359,186.032C215.537,184.722 212.558,183.426 209.484,182.171C213.819,180.141 217.374,178.148 220.016,176.226C220.449,175.98 220.869,175.548 221.265,175.133C222.226,174.11 223.498,172.731 224.999,171.329L225.804,170.59L226.585,171.346C234.884,179.137 244.034,183.412 252.381,183.412C261.16,183.412 270.216,179.611 278.55,172.418L279.151,171.925L280.827,172.736C282.364,174.156 285.156,176.176 286.405,176.8L287.846,177.497L287.678,177.677L288.59,178.206C290.176,179.148 291.869,180.055 293.767,180.991C295.712,181.856 297.381,182.516 299.135,183.093C299.477,183.208 307.638,185.831 317.053,190.191L318.716,190.709C327.297,193.98 331.027,198.49 331.393,198.959C345.264,219.531 347.497,264.1 347.707,269.059C347.605,275.947 345.695,277.718 345.216,278.025C319.118,289.704 281.661,294.087 265.899,295.481C264.475,275.028 259.431,226.846 242.57,201.782L241.855,200.924C238.439,196.69 230.957,190.697 220.082,186.53ZM210.318,112.073L210.613,111.722C211.933,110.758 212.582,109.263 212.33,107.72C209.195,88.892 211.226,80.996 211.934,79.017C217.399,62.249 234.596,54.434 237.959,53.05C238.644,52.791 239.952,52.398 241.346,52.164L241.766,52.059L244.36,51.924L244.384,52.104L245.164,52.035C245.753,51.987 246.317,51.9 246.708,51.813L247.578,51.618C248.131,51.636 254.922,52.51 264.764,55.521L271.694,57.908C284.293,61.628 290.129,68.576 291.21,69.984C301.328,81.477 298.62,98.756 296.086,108.046C295.81,109.196 295.978,110.364 296.639,111.318L297.198,112.039C297.912,112.991 298.554,116.783 296.363,124.967C295.955,127.447 295.03,129.438 293.709,130.762C293.169,131.32 292.814,132.047 292.688,132.887C289.265,152.946 271.298,175.374 252.383,175.374C236.303,175.374 217.976,154.735 214.685,132.887C214.553,132.053 214.199,131.326 213.605,130.662C212.272,129.272 211.401,127.243 210.867,124.18C209.267,118.505 209.099,113.917 210.318,112.073ZM70.479,90.453L70.914,89.949C72.607,88.727 73.424,86.799 73.118,84.827C68.872,59.315 71.64,48.702 72.601,46.039C79.978,23.374 103.241,12.787 107.813,10.905C108.768,10.535 110.545,10.001 112.419,9.701L112.923,9.584L116.76,9.368L116.772,9.614L117.598,9.527C118.367,9.455 119.111,9.344 119.991,9.164L120.862,8.957C121.576,8.963 130.553,10.095 144.1,14.238L153.423,17.442C170.446,22.477 178.379,31.904 179.832,33.778C193.523,49.324 189.872,72.713 186.474,85.275C186.083,86.722 186.318,88.235 187.134,89.463L187.891,90.436C189.14,92.108 189.609,97.705 186.823,108.063C186.259,111.447 185.003,114.188 183.16,116.007C182.493,116.728 182.052,117.667 181.863,118.721C177.23,145.842 152.92,176.178 127.321,176.178C105.56,176.178 80.748,148.265 76.271,118.74C76.124,117.689 75.688,116.722 74.914,115.893C73.056,113.965 71.864,111.188 71.137,107.063C68.983,99.295 68.77,93.047 70.479,90.453Z" style="fill:url(#_Linear3);fill-rule:nonzero;"/>';
265 $source .= '</g>';
266 $source .= '</g>';
267 $source .= '<defs>';
268 $source .= '<linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1,0,0,-1,0,0)"><stop offset="0" style="stop-color:rgb(25,39,131);stop-opacity:1"/><stop offset="1" style="stop-color:rgb(65,172,255);stop-opacity:1"/></linearGradient>';
269 $source .= '<linearGradient id="_Linear2" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1,0,0,-1,0,0)"><stop offset="0" style="stop-color:rgb(25,39,131);stop-opacity:1"/><stop offset="1" style="stop-color:rgb(65,172,255);stop-opacity:1"/></linearGradient>';
270 $source .= '<linearGradient id="_Linear3" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(524.215,0,0,-931.414,-30.669,173.855)"><stop offset="0" style="stop-color:rgb(255,147,8);stop-opacity:1"/><stop offset="1" style="stop-color:rgb(255,216,111);stop-opacity:1"/></linearGradient>';
271 $source .= '</defs>';
272 $source .= '</svg>';
273
274 // phpcs:ignore
275 return 'data:image/svg+xml;base64,' . base64_encode( $source );
276 }
277
278 }
279