Admin
2 years ago
Commands
2 years ago
Db
2 years ago
Ecommerce
2 years ago
Report
2 years ago
Site
2 years ago
TrackingCode
2 years ago
Updater
4 years ago
User
2 years ago
Workarounds
2 years ago
WpStatistics
2 years ago
views
4 years ago
API.php
2 years ago
Access.php
4 years ago
AjaxTracker.php
2 years ago
Annotations.php
4 years ago
Bootstrap.php
2 years ago
Capabilities.php
4 years ago
Compatibility.php
2 years ago
Email.php
2 years ago
ErrorNotice.php
2 years ago
Installer.php
2 years ago
Logger.php
2 years ago
OptOut.php
4 years ago
Paths.php
2 years ago
PluginAdminOverrides.php
2 years ago
PrivacyBadge.php
4 years ago
RedirectOnActivation.php
4 years ago
Referral.php
4 years ago
Roles.php
4 years ago
ScheduledTasks.php
2 years ago
Settings.php
2 years ago
Site.php
3 years ago
TrackingCode.php
4 years ago
Uninstaller.php
2 years ago
Updater.php
2 years ago
User.php
4 years ago
Bootstrap.php
135 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Matomo - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * @package matomo |
| 8 | */ |
| 9 | |
| 10 | namespace WpMatomo; |
| 11 | |
| 12 | use Piwik\Application\Environment; |
| 13 | use Piwik\FrontController; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; // if accessed directly |
| 17 | } |
| 18 | /** |
| 19 | * piwik constants |
| 20 | * phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound |
| 21 | */ |
| 22 | class Bootstrap { |
| 23 | /** |
| 24 | * Tests only |
| 25 | * |
| 26 | * @var bool|null |
| 27 | */ |
| 28 | private static $assume_not_bootstrapped; |
| 29 | |
| 30 | private static $bootstrapped_by_wordpress = false; |
| 31 | |
| 32 | private static $are_incompatible_plugins_filtered = false; |
| 33 | |
| 34 | private static $extra_di_definitions = []; |
| 35 | |
| 36 | public static function set_extra_di_definitions( array $definitions ) { |
| 37 | if ( ! defined( 'PIWIK_TEST_MODE' ) ) { |
| 38 | throw new \Exception( 'set_extra_di_definitions is only for tests' ); |
| 39 | } |
| 40 | |
| 41 | self::$extra_di_definitions = $definitions; |
| 42 | } |
| 43 | |
| 44 | public static function get_extra_di_definitions() { |
| 45 | return self::$extra_di_definitions; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Tests only |
| 50 | * |
| 51 | * @internal |
| 52 | * @ignore |
| 53 | */ |
| 54 | public static function set_not_bootstrapped() { |
| 55 | self::$assume_not_bootstrapped = true; |
| 56 | self::$bootstrapped_by_wordpress = false; |
| 57 | } |
| 58 | |
| 59 | public static function was_bootstrapped_by_wordpress() { |
| 60 | return self::$bootstrapped_by_wordpress; |
| 61 | } |
| 62 | |
| 63 | public function bootstrap() { |
| 64 | if ( self::is_bootstrapped() ) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | self::$bootstrapped_by_wordpress = true; |
| 69 | self::$assume_not_bootstrapped = false; // we need to unset it again to prevent recursion |
| 70 | |
| 71 | if ( ! self::$are_incompatible_plugins_filtered ) { |
| 72 | matomo_filter_incompatible_plugins( $GLOBALS['MATOMO_PLUGINS_ENABLED'] ); |
| 73 | |
| 74 | self::$are_incompatible_plugins_filtered = true; |
| 75 | } |
| 76 | |
| 77 | if ( ! defined( 'PIWIK_ENABLE_DISPATCH' ) ) { |
| 78 | define( 'PIWIK_ENABLE_DISPATCH', false ); |
| 79 | } |
| 80 | |
| 81 | // prevent session related errors during install making it more stable |
| 82 | if ( ! defined( 'PIWIK_ENABLE_SESSION_START' ) ) { |
| 83 | define( 'PIWIK_ENABLE_SESSION_START', false ); |
| 84 | } |
| 85 | |
| 86 | if ( ! defined( 'PIWIK_DOCUMENT_ROOT' ) ) { |
| 87 | define( 'PIWIK_DOCUMENT_ROOT', plugin_dir_path( MATOMO_ANALYTICS_FILE ) . 'app' ); |
| 88 | } |
| 89 | |
| 90 | require_once PIWIK_DOCUMENT_ROOT . '/bootstrap.php'; |
| 91 | |
| 92 | if ( ! defined( 'PIWIK_INCLUDE_PATH' ) ) { |
| 93 | define( 'PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT ); |
| 94 | } |
| 95 | |
| 96 | require_once PIWIK_INCLUDE_PATH . '/core/bootstrap.php'; |
| 97 | // we need to install now |
| 98 | |
| 99 | include_once 'Db/WordPress.php'; |
| 100 | |
| 101 | $environment = new Environment( null, self::$extra_di_definitions ); |
| 102 | $environment->init(); |
| 103 | |
| 104 | FrontController::unsetInstance(); |
| 105 | $controller = FrontController::getInstance(); |
| 106 | $controller->init(); |
| 107 | |
| 108 | add_action( |
| 109 | 'set_current_user', |
| 110 | function () { |
| 111 | $access = \Piwik\Access::getInstance(); |
| 112 | if ( $access ) { |
| 113 | $access->reloadAccess(); |
| 114 | } |
| 115 | } |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | public static function is_bootstrapped() { |
| 120 | if ( true === self::$assume_not_bootstrapped ) { |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | return defined( 'PIWIK_DOCUMENT_ROOT' ); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @api |
| 129 | */ |
| 130 | public static function do_bootstrap() { |
| 131 | $bootstrap = new Bootstrap(); |
| 132 | $bootstrap->bootstrap(); |
| 133 | } |
| 134 | } |
| 135 |