Admin
3 years ago
Commands
4 years ago
Db
4 years ago
Ecommerce
3 years ago
Report
4 years ago
Site
3 years ago
TrackingCode
4 years ago
Updater
4 years ago
User
3 years ago
WpStatistics
4 years ago
views
4 years ago
API.php
4 years ago
Access.php
4 years ago
AjaxTracker.php
5 years ago
Annotations.php
4 years ago
Bootstrap.php
4 years ago
Capabilities.php
4 years ago
Compatibility.php
4 years ago
Email.php
4 years ago
Installer.php
4 years ago
Logger.php
4 years ago
OptOut.php
4 years ago
Paths.php
4 years ago
PrivacyBadge.php
4 years ago
RedirectOnActivation.php
4 years ago
Referral.php
4 years ago
Roles.php
4 years ago
ScheduledTasks.php
4 years ago
Settings.php
4 years ago
Site.php
3 years ago
TrackingCode.php
4 years ago
Uninstaller.php
4 years ago
Updater.php
4 years ago
User.php
4 years ago
Bootstrap.php
113 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 | /** |
| 33 | * Tests only |
| 34 | * |
| 35 | * @internal |
| 36 | * @ignore |
| 37 | */ |
| 38 | public static function set_not_bootstrapped() { |
| 39 | self::$assume_not_bootstrapped = true; |
| 40 | self::$bootstrapped_by_wordpress = false; |
| 41 | } |
| 42 | |
| 43 | public static function was_bootstrapped_by_wordpress() { |
| 44 | return self::$bootstrapped_by_wordpress; |
| 45 | } |
| 46 | |
| 47 | public function bootstrap() { |
| 48 | if ( self::is_bootstrapped() ) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | self::$bootstrapped_by_wordpress = true; |
| 53 | self::$assume_not_bootstrapped = false; // we need to unset it again to prevent recursion |
| 54 | |
| 55 | if ( ! defined( 'PIWIK_ENABLE_DISPATCH' ) ) { |
| 56 | define( 'PIWIK_ENABLE_DISPATCH', false ); |
| 57 | } |
| 58 | |
| 59 | // prevent session related errors during install making it more stable |
| 60 | if ( ! defined( 'PIWIK_ENABLE_SESSION_START' ) ) { |
| 61 | define( 'PIWIK_ENABLE_SESSION_START', false ); |
| 62 | } |
| 63 | |
| 64 | if ( ! defined( 'PIWIK_DOCUMENT_ROOT' ) ) { |
| 65 | define( 'PIWIK_DOCUMENT_ROOT', plugin_dir_path( MATOMO_ANALYTICS_FILE ) . 'app' ); |
| 66 | } |
| 67 | |
| 68 | require_once PIWIK_DOCUMENT_ROOT . '/bootstrap.php'; |
| 69 | |
| 70 | if ( ! defined( 'PIWIK_INCLUDE_PATH' ) ) { |
| 71 | define( 'PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT ); |
| 72 | } |
| 73 | |
| 74 | require_once PIWIK_INCLUDE_PATH . '/core/bootstrap.php'; |
| 75 | // we need to install now |
| 76 | |
| 77 | include_once 'Db/WordPress.php'; |
| 78 | |
| 79 | $environment = new Environment( null ); |
| 80 | $environment->init(); |
| 81 | |
| 82 | FrontController::unsetInstance(); |
| 83 | $controller = FrontController::getInstance(); |
| 84 | $controller->init(); |
| 85 | |
| 86 | add_action( |
| 87 | 'set_current_user', |
| 88 | function () { |
| 89 | $access = \Piwik\Access::getInstance(); |
| 90 | if ( $access ) { |
| 91 | $access->reloadAccess(); |
| 92 | } |
| 93 | } |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | public static function is_bootstrapped() { |
| 98 | if ( true === self::$assume_not_bootstrapped ) { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | return defined( 'PIWIK_DOCUMENT_ROOT' ); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @api |
| 107 | */ |
| 108 | public static function do_bootstrap() { |
| 109 | $bootstrap = new Bootstrap(); |
| 110 | $bootstrap->bootstrap(); |
| 111 | } |
| 112 | } |
| 113 |