| 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 Decalog\Plugin; |
| 14 |
|
| 15 |
use Decalog\System\Loader; |
| 16 |
use Decalog\Plugin\Initializer; |
| 17 |
use Decalog\System\I18n; |
| 18 |
use Decalog\System\Assets; |
| 19 |
use Decalog\Library\Libraries; |
| 20 |
use Decalog\System\Nag; |
| 21 |
use Decalog\Plugin\Feature\LoggerMaintainer; |
| 22 |
use Decalog\Listener\ListenerFactory; |
| 23 |
use Decalog\Integration\IntegrationsLoader; |
| 24 |
use Decalog\LoggerRoute; |
| 25 |
use Decalog\MonitorRoute; |
| 26 |
|
| 27 |
/** |
| 28 |
* The core plugin class. |
| 29 |
* |
| 30 |
* This is used to define internationalization, admin-specific hooks, and |
| 31 |
* public-facing site hooks. |
| 32 |
* |
| 33 |
* @package Plugin |
| 34 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 35 |
* @since 1.0.0 |
| 36 |
*/ |
| 37 |
class Core { |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* The loader that's responsible for maintaining and registering all hooks that power |
| 42 |
* the plugin. |
| 43 |
* |
| 44 |
* @since 1.0.0 |
| 45 |
* @var Loader $loader Maintains and registers all hooks for the plugin. |
| 46 |
*/ |
| 47 |
protected $loader; |
| 48 |
|
| 49 |
/** |
| 50 |
* Define the core functionality of the plugin. |
| 51 |
* |
| 52 |
* Load the dependencies, define the locale, and set the hooks for the admin area and |
| 53 |
* the public-facing side of the site. |
| 54 |
* |
| 55 |
* @since 1.0.0 |
| 56 |
*/ |
| 57 |
public function __construct() { |
| 58 |
$this->loader = new Loader(); |
| 59 |
$this->define_global_hooks(); |
| 60 |
$this->define_admin_hooks(); |
| 61 |
$this->define_public_hooks(); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Register all of the hooks related to the features of the plugin. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
*/ |
| 69 |
private function define_global_hooks() { |
| 70 |
$bootstrap = new Initializer(); |
| 71 |
$assets = new Assets(); |
| 72 |
$updater = new Updater(); |
| 73 |
$libraries = new Libraries(); |
| 74 |
$listeners = new ListenerFactory(); |
| 75 |
$this->loader->add_filter( 'perfopsone_plugin_info', self::class, 'perfopsone_plugin_info' ); |
| 76 |
$this->loader->add_action( 'init', $bootstrap, 'initialize', 0 ); |
| 77 |
$this->loader->add_action( 'init', $bootstrap, 'late_initialize', PHP_INT_MAX ); |
| 78 |
$this->loader->add_action( 'plugins_loaded', $listeners, 'launch', PHP_INT_MIN, 0 ); |
| 79 |
$this->loader->add_action( 'plugins_loaded', $listeners, 'late_launch', PHP_INT_MAX, 0 ); |
| 80 |
$this->loader->add_action( 'wp_head', $assets, 'prefetch' ); |
| 81 |
add_shortcode( 'decalog-changelog', [ $updater, 'sc_get_changelog' ] ); |
| 82 |
add_shortcode( 'decalog-libraries', [ $libraries, 'sc_get_list' ] ); |
| 83 |
add_shortcode( 'decalog-statistics', [ 'Decalog\System\Statistics', 'sc_get_raw' ] ); |
| 84 |
add_shortcode( 'decalog-help-logging', [ 'Decalog\Plugin\Feature\InlineHelp', 'sc_get_logging' ] ); |
| 85 |
add_shortcode( 'decalog-help-monitoring', [ 'Decalog\Plugin\Feature\InlineHelp', 'sc_get_monitoring' ] ); |
| 86 |
add_shortcode( 'decalog-help-tracing', [ 'Decalog\Plugin\Feature\InlineHelp', 'sc_get_tracing' ] ); |
| 87 |
if ( ! wp_next_scheduled( DECALOG_CRON_NAME ) ) { |
| 88 |
wp_schedule_event( time(), 'hourly', DECALOG_CRON_NAME ); |
| 89 |
} |
| 90 |
$maintainer = new LoggerMaintainer(); |
| 91 |
$this->loader->add_action( DECALOG_CRON_NAME, $maintainer, 'cron_clean' ); |
| 92 |
$integrations_loader = new IntegrationsLoader(); |
| 93 |
$integrations_loader->load_psr3(); |
| 94 |
// REST API |
| 95 |
$this->loader->add_action( 'rest_api_init', new LoggerRoute(), 'register_routes' ); |
| 96 |
$this->loader->add_action( 'rest_api_init', new MonitorRoute(), 'register_routes' ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Register all of the hooks related to the admin area functionality |
| 101 |
* of the plugin. |
| 102 |
* |
| 103 |
* @since 1.0.0 |
| 104 |
*/ |
| 105 |
private function define_admin_hooks() { |
| 106 |
$plugin_admin = new Decalog_Admin(); |
| 107 |
$nag = new Nag(); |
| 108 |
$this->loader->add_action( 'init', $plugin_admin, 'disable_wp_emojis', PHP_INT_MAX ); |
| 109 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'register_styles' ); |
| 110 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'register_scripts' ); |
| 111 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'init_admin_menus' ); |
| 112 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'finalize_admin_menus', 100 ); |
| 113 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'normalize_admin_menus', 110 ); |
| 114 |
$this->loader->add_action( 'admin_init', $plugin_admin, 'init_settings_sections' ); |
| 115 |
$this->loader->add_filter( 'plugin_action_links_' . plugin_basename( DECALOG_PLUGIN_DIR . DECALOG_SLUG . '.php' ), $plugin_admin, 'add_actions_links', 10, 4 ); |
| 116 |
$this->loader->add_filter( 'plugin_row_meta', $plugin_admin, 'add_row_meta', 10, 2 ); |
| 117 |
$this->loader->add_action( 'admin_notices', $nag, 'display' ); |
| 118 |
$this->loader->add_action( 'wp_ajax_hide_decalog_nag', $nag, 'hide_callback' ); |
| 119 |
$this->loader->add_filter( 'myblogs_blog_actions', $plugin_admin, 'blog_action', 10, 2 ); |
| 120 |
$this->loader->add_filter( 'manage_sites_action_links', $plugin_admin, 'site_action', 10, 3 ); |
| 121 |
add_shortcode( 'decalog-selfreg', [ 'Decalog\Plugin\Feature\SDK', 'sc_get_selfreg' ] ); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Register all of the hooks related to the public-facing functionality |
| 126 |
* of the plugin. |
| 127 |
* |
| 128 |
* @since 1.0.0 |
| 129 |
*/ |
| 130 |
private function define_public_hooks() { |
| 131 |
$plugin_public = new Decalog_Public(); |
| 132 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_styles' ); |
| 133 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_scripts' ); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Run the loader to execute all of the hooks with WordPress. |
| 138 |
* |
| 139 |
* @since 1.0.0 |
| 140 |
*/ |
| 141 |
public function run() { |
| 142 |
$this->loader->run(); |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 147 |
* |
| 148 |
* @since 1.0.0 |
| 149 |
* @return Loader Orchestrates the hooks of the plugin. |
| 150 |
*/ |
| 151 |
public function get_loader() { |
| 152 |
return $this->loader; |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Adds full plugin identification. |
| 157 |
* |
| 158 |
* @param array $plugin The already set identification information. |
| 159 |
* @return array The extended identification information. |
| 160 |
* @since 1.0.0 |
| 161 |
*/ |
| 162 |
public static function perfopsone_plugin_info( $plugin ) { |
| 163 |
$plugin[ DECALOG_SLUG ] = [ |
| 164 |
'name' => DECALOG_PRODUCT_NAME, |
| 165 |
'code' => DECALOG_CODENAME, |
| 166 |
'version' => DECALOG_VERSION, |
| 167 |
'url' => DECALOG_PRODUCT_URL, |
| 168 |
'icon' => self::get_base64_logo(), |
| 169 |
]; |
| 170 |
return $plugin; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Returns a base64 svg resource for the plugin logo. |
| 175 |
* |
| 176 |
* @return string The svg resource as a base64. |
| 177 |
* @since 1.5.0 |
| 178 |
*/ |
| 179 |
public static function get_base64_logo() { |
| 180 |
$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-miterlimit:10;">'; |
| 181 |
$source .= '<g id="DecaLog" transform="matrix(10.0067,0,0,10.0067,0,0)">'; |
| 182 |
$source .= '<rect x="0" y="0" width="100" height="100" style="fill:none;"/>'; |
| 183 |
$source .= '<clipPath id="_clip1"><rect x="0" y="0" width="100" height="100"/></clipPath>'; |
| 184 |
$source .= '<g clip-path="url(#_clip1)">'; |
| 185 |
$source .= '<g id="Icon" transform="matrix(0.964549,0,0,0.964549,-0.63865,1.78035)">'; |
| 186 |
$source .= '<g transform="matrix(0,1,1,0,60.0193,87.9577)"><path d="M-7.5,-7.5L7.5,-7.5" style="fill:none;fill-rule:nonzero;stroke:rgb(87,159,244);stroke-width:1.73px;"/></g>'; |
| 187 |
$source .= '<g transform="matrix(1,0,0,1,7.51934,95.4577)"><path d="M0,0L90,0" style="fill:none;fill-rule:nonzero;stroke:rgb(87,159,244);stroke-width:1.73px;"/></g>'; |
| 188 |
$source .= '<g transform="matrix(-1,0,0,1,103.001,83.2866)"><rect x="44" y="9" width="13" height="6" style="fill:rgb(171,207,249);stroke:rgb(171,207,249);stroke-width:1.73px;stroke-linecap:round;stroke-linejoin:round;"/></g>'; |
| 189 |
$source .= '<g transform="matrix(-74.0061,0,0,69.5617,89.7095,37.9131)"><path d="M0.932,-0.161C0.969,-0.161 1,-0.13 1,-0.093L1,0.093C1,0.13 0.969,0.161 0.932,0.161L0.079,0.161C0.041,0.161 0.01,0.13 0.01,0.093L0.01,-0.093C0.01,-0.13 0.041,-0.161 0.079,-0.161L0.932,-0.161Z" style="fill:url(#_Linear2);fill-rule:nonzero;"/></g>'; |
| 190 |
$source .= '<g transform="matrix(0,-1.72045,-1.83038,0,27.617,35.3325)"><path d="M-1.5,-1.5C-2.329,-1.5 -3,-0.829 -3,0C-3,0.829 -2.329,1.5 -1.5,1.5C-0.671,1.5 0,0.829 0,0C0,-0.829 -0.671,-1.5 -1.5,-1.5" style="fill:white;fill-rule:nonzero;"/></g>'; |
| 191 |
$source .= '<g transform="matrix(1.83038,0,0,1.72045,80.0045,37.0529)"><path d="M0,2L-15.242,2C-15.728,2 -16.121,1.606 -16.121,1.121L-16.121,0.879C-16.121,0.394 -15.728,0 -15.242,0L0,0C0.485,0 0.879,0.394 0.879,0.879L0.879,1.121C0.879,1.606 0.485,2 0,2" style="fill:white;fill-rule:nonzero;"/></g>'; |
| 192 |
$source .= '<g transform="matrix(-74.0061,0,0,69.5617,89.7095,13.8268)"><path d="M0.932,-0.161C0.969,-0.161 1,-0.13 1,-0.093L1,0.093C1,0.13 0.969,0.161 0.932,0.161L0.079,0.161C0.041,0.161 0.01,0.13 0.01,0.093L0.01,-0.093C0.01,-0.13 0.041,-0.161 0.079,-0.161L0.932,-0.161Z" style="fill:url(#_Linear3);fill-rule:nonzero;"/></g>'; |
| 193 |
$source .= '<g transform="matrix(0,-1.72045,-1.83038,0,27.617,11.2461)"><path d="M-1.5,-1.5C-2.329,-1.5 -3,-0.829 -3,0C-3,0.829 -2.329,1.5 -1.5,1.5C-0.671,1.5 0,0.829 0,0C0,-0.829 -0.671,-1.5 -1.5,-1.5" style="fill:white;fill-rule:nonzero;"/></g>'; |
| 194 |
$source .= '<g transform="matrix(1.83038,0,0,1.72045,80.0045,11.2461)"><path d="M0,2L-15.242,2C-15.728,2 -16.121,1.606 -16.121,1.121L-16.121,0.879C-16.121,0.394 -15.728,0 -15.242,0L0,0C0.485,0 0.879,0.394 0.879,0.879L0.879,1.121C0.879,1.606 0.485,2 0,2" style="fill:white;fill-rule:nonzero;"/></g>'; |
| 195 |
$source .= '<g transform="matrix(-74.0061,0,0,69.5617,89.7095,61.9995)"><path d="M0.932,-0.161C0.969,-0.161 1,-0.13 1,-0.093L1,0.093C1,0.13 0.969,0.161 0.932,0.161L0.079,0.161C0.041,0.161 0.01,0.13 0.01,0.093L0.01,-0.093C0.01,-0.13 0.041,-0.161 0.079,-0.161L0.932,-0.161Z" style="fill:url(#_Linear4);fill-rule:nonzero;"/></g>'; |
| 196 |
$source .= '<g transform="matrix(0,-1.72045,-1.83038,0,27.617,61.1393)"><path d="M-1.5,-1.5C-2.329,-1.5 -3,-0.829 -3,0C-3,0.829 -2.329,1.5 -1.5,1.5C-0.671,1.5 0,0.829 0,0C0,-0.829 -0.671,-1.5 -1.5,-1.5" style="fill:white;fill-rule:nonzero;"/></g>'; |
| 197 |
$source .= '<g transform="matrix(1.83038,0,0,1.72045,80.0045,61.1393)"><path d="M0,2L-15.242,2C-15.728,2 -16.121,1.606 -16.121,1.121L-16.121,0.879C-16.121,0.394 -15.728,0 -15.242,0L0,0C0.485,0 0.879,0.394 0.879,0.879L0.879,1.121C0.879,1.606 0.485,2 0,2" style="fill:white;fill-rule:nonzero;"/></g>'; |
| 198 |
$source .= '<g transform="matrix(0,102.342,95.773,0,52.6879,3.58289)"><path d="M0.217,-0.035L0.661,-0.295C0.674,-0.303 0.69,-0.303 0.703,-0.296C0.716,-0.289 0.724,-0.275 0.724,-0.26L0.724,0.26C0.724,0.275 0.716,0.289 0.703,0.296C0.69,0.303 0.674,0.303 0.661,0.295L0.216,0.035C0.204,0.027 0.197,0.014 0.197,0C0.197,-0.014 0.204,-0.027 0.217,-0.035Z" style="fill:url(#_Linear5);fill-rule:nonzero;"/></g>'; |
| 199 |
$source .= '<g transform="matrix(0,-66.7731,-62.4871,0,52.6897,87.2624)"><path d="M0.906,0.03L0.225,0.428C0.201,0.443 0.17,0.426 0.17,0.398L0.17,-0.398C0.17,-0.426 0.201,-0.443 0.225,-0.428L0.906,-0.03C0.917,-0.023 0.922,-0.012 0.922,0C0.922,0.012 0.917,0.023 0.906,0.03Z" style="fill:url(#_Linear6);fill-rule:nonzero;"/></g>'; |
| 200 |
$source .= '<g transform="matrix(1.6838,0,0,1.7993,54.7887,65.0716)"><path d="M0,-11.978L-0.395,-3.716C-0.415,-3.26 -0.685,-2.928 -1.267,-2.928C-1.889,-2.928 -2.159,-3.26 -2.18,-3.716L-2.553,-11.978C-2.595,-12.787 -2.097,-13.14 -1.267,-13.14C-0.457,-13.14 0.042,-12.787 0,-11.978M-2.636,-0.187C-2.636,-1.122 -2.138,-1.579 -1.267,-1.579C-0.395,-1.579 0.083,-1.122 0.083,-0.187C0.083,0.726 -0.395,1.162 -1.267,1.162C-2.138,1.162 -2.636,0.726 -2.636,-0.187" style="fill:white;fill-rule:nonzero;"/></g>'; |
| 201 |
$source .= '</g>'; |
| 202 |
$source .= '</g>'; |
| 203 |
$source .= '</g>'; |
| 204 |
$source .= '<defs>'; |
| 205 |
$source .= '<linearGradient id="_Linear2" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1,0,0,-1,0,-5.55112e-17)"><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>'; |
| 206 |
$source .= '<linearGradient id="_Linear3" 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>'; |
| 207 |
$source .= '<linearGradient id="_Linear4" 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>'; |
| 208 |
$source .= '<linearGradient id="_Linear5" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1,0,0,-1,0,1.85025e-05)"><stop offset="0" style="stop-color:rgb(248,247,252);stop-opacity:1"/><stop offset="0.08" style="stop-color:rgb(248,247,252);stop-opacity:1"/><stop offset="1" style="stop-color:rgb(65,172,255);stop-opacity:1"/></linearGradient>'; |
| 209 |
$source .= '<linearGradient id="_Linear6" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1,0,0,-1,0,2.88974e-05)"><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>'; |
| 210 |
$source .= '</defs>'; |
| 211 |
$source .= '</svg>'; |
| 212 |
// phpcs:ignore |
| 213 |
return 'data:image/svg+xml;base64,' . base64_encode( $source ); |
| 214 |
} |
| 215 |
|
| 216 |
} |
| 217 |
|