.htaccess
6 years ago
common.config.ini.php
6 years ago
config.php
5 years ago
index.php
6 years ago
config.php
179 lines
| 1 | <?php |
| 2 | |
| 3 | if (!defined( 'ABSPATH')) { |
| 4 | exit; // if accessed directly |
| 5 | } |
| 6 | |
| 7 | use Piwik\Cache; |
| 8 | use Piwik\Container\StaticContainer; |
| 9 | use Piwik\Option; |
| 10 | use Piwik\Plugin\API; |
| 11 | use WpMatomo\Capabilities; |
| 12 | use WpMatomo\Paths; |
| 13 | use WpMatomo\Settings; |
| 14 | |
| 15 | return array( |
| 16 | 'path.tmp' => function () { |
| 17 | $paths = new \WpMatomo\Paths(); |
| 18 | return $paths->get_tmp_dir(); |
| 19 | }, |
| 20 | 'path.misc.user' => function () { |
| 21 | $paths = new \WpMatomo\Paths(); |
| 22 | return $paths->get_relative_dir_to_matomo($paths->get_upload_base_dir()) . '/'; |
| 23 | }, |
| 24 | 'log.handlers' => array(), // required in the console |
| 25 | 'EnableDbVersionCheck' => false, |
| 26 | 'path.geoip2' => function () { |
| 27 | $paths = new \WpMatomo\Paths(); |
| 28 | return $paths->get_gloal_upload_dir_if_possible('DBIP-City.mmdb') . '/'; |
| 29 | }, |
| 30 | // we want to avoid the regular monolog logger as it could interfere with other plugins maybe. for now lets use a |
| 31 | // custom logger |
| 32 | 'Psr\Log\LoggerInterface' => DI\get('\Piwik\Plugins\WordPress\Logger'), |
| 33 | 'TagManagerContainerStorageDir' => function () { |
| 34 | // the location where we store the generated javascript or json container files |
| 35 | $paths = new \WpMatomo\Paths(); |
| 36 | return rtrim('/'. $paths->get_relative_dir_to_matomo($paths->get_upload_base_dir().'/'), '/'); |
| 37 | }, |
| 38 | 'TagManagerContainerWebDir' => function () { |
| 39 | // the location where we store the generated javascript or json container files |
| 40 | $paths = new \WpMatomo\Paths(); |
| 41 | return rtrim('/'. $paths->get_relative_dir_to_matomo($paths->get_upload_base_dir().'/'), '/'); |
| 42 | }, |
| 43 | 'Piwik\Auth' => DI\object('Piwik\Plugins\WordPress\Auth'), |
| 44 | \Piwik\Config::class => DI\decorate(function ($previous) { |
| 45 | |
| 46 | \Piwik\Plugins\TagManager\TagManager::$enableAutoContainerCreation = false; |
| 47 | |
| 48 | if (defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN) { |
| 49 | $general = $previous->General; |
| 50 | $general['force_ssl'] = 1; |
| 51 | $general['assume_secure_protocol'] = 1; |
| 52 | $previous->General = $general; |
| 53 | } |
| 54 | |
| 55 | $database = $previous->database; |
| 56 | $previous->database = \WpMatomo\Installer::get_db_infos($database); |
| 57 | |
| 58 | $paths = new Paths(); |
| 59 | if ( file_exists( $paths->get_config_ini_path() ) ) { |
| 60 | $general = $previous->General; |
| 61 | |
| 62 | if (defined('MATOMO_TRIGGER_BROWSER_ARCHIVING')) { |
| 63 | $general['enable_browser_archiving_triggering'] = (int) MATOMO_TRIGGER_BROWSER_ARCHIVING; |
| 64 | } |
| 65 | |
| 66 | $matomo_salt_key = Settings::OPTION_PREFIX . 'matomo_salt'; |
| 67 | $matomo_salt = get_option($matomo_salt_key); // needs to be per site! |
| 68 | if (!$matomo_salt) { |
| 69 | $matomo_salt = \Piwik\Common::getRandomString(32); |
| 70 | update_option($matomo_salt_key, $matomo_salt, true); |
| 71 | } |
| 72 | |
| 73 | $general['salt'] = $matomo_salt; |
| 74 | |
| 75 | if (empty($general['trusted_hosts'])) { |
| 76 | $general['trusted_hosts'] = array(); |
| 77 | } |
| 78 | if (!in_array(site_url(), $general['trusted_hosts'])) { |
| 79 | $general['trusted_hosts'][] = site_url(); |
| 80 | } |
| 81 | $previous->General = $general; |
| 82 | |
| 83 | if (empty($GLOBALS['MATOMO_SWITCH_BLOG_SET_UP'])) { |
| 84 | // only execute it once since we might init this several times... |
| 85 | $GLOBALS['MATOMO_SWITCH_BLOG_SET_UP'] = true; |
| 86 | |
| 87 | add_action('switch_blog', function ($new_blog, $prev_blog) { |
| 88 | if ($new_blog == $prev_blog) { |
| 89 | return; |
| 90 | } |
| 91 | // ensure correct path to config is set, ensure to update tables_prefix etc. |
| 92 | $container = StaticContainer::getContainer(); |
| 93 | $container->set(\Piwik\Application\Kernel\GlobalSettingsProvider::class, $container->make(\Piwik\Application\Kernel\GlobalSettingsProvider::class)); |
| 94 | $container->set(\Piwik\Config::class, $container->make(\Piwik\Config::class)); |
| 95 | Option::clearCache(); |
| 96 | \Piwik\Site::clearCache(); |
| 97 | Cache::getTransientCache()->flushAll(); |
| 98 | API::unsetAllInstances(); |
| 99 | }, 10, 2); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return $previous; |
| 104 | }), |
| 105 | 'Zend_Mail_Transport_Abstract' => DI\object('WpMatomo\Email'), |
| 106 | 'Piwik\Plugins\CustomPiwikJs\TrackerUpdater' => DI\decorate(function ($previous) { |
| 107 | /** @var \Piwik\Plugins\CustomPiwikJs\TrackerUpdater $previous */ |
| 108 | |
| 109 | $paths = new Paths(); |
| 110 | $dir = $paths->get_matomo_js_upload_path(); |
| 111 | |
| 112 | $previous->setToFile($dir); |
| 113 | |
| 114 | return $previous; |
| 115 | }), |
| 116 | 'diagnostics.optional' => DI\decorate(function ($checks) { |
| 117 | foreach ($checks as $index => $check) { |
| 118 | if ($check && is_object($check)) { |
| 119 | $class_name = get_class($check); |
| 120 | if ($class_name === 'Piwik\Plugins\Diagnostics\Diagnostic\ForceSSLCheck' |
| 121 | || $class_name === 'Piwik\Plugins\Diagnostics\Diagnostic\LoadDataInfileCheck' |
| 122 | || $class_name === 'Piwik\Plugins\Diagnostics\Diagnostic\FileIntegrityCheck') { |
| 123 | $checks[$index] = null; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | return array_values(array_filter($checks)); |
| 128 | }), |
| 129 | 'observers.global' => DI\add(array( |
| 130 | array('FrontController.modifyErrorPage', function (&$result, $ex) { |
| 131 | if (!empty($ex) && is_object($ex) && $ex instanceof \Piwik\Exception\NoWebsiteFoundException) { |
| 132 | // try to repair itself in case for some reason the site was not yet synced... on next reload it would |
| 133 | // then work |
| 134 | $sync = new \WpMatomo\Site\Sync(new Settings()); |
| 135 | $sync->sync_current_site(); |
| 136 | } |
| 137 | if (!empty($ex) |
| 138 | && is_object($ex) |
| 139 | && $ex instanceof \Piwik\Exception\NoPrivilegesException |
| 140 | && is_user_logged_in()) { |
| 141 | if (current_user_can(Capabilities::KEY_VIEW)) { |
| 142 | // some error... it looks like user should by synced but isn't yet |
| 143 | // could happen eg when in network activated mode the super admin changes permission and another |
| 144 | // user from a blog wants to access the UI while not all users are synced just yet |
| 145 | // try to repair itself in case for some reason the user was not yet synced... on next reload it would |
| 146 | // then work |
| 147 | $sync = new \WpMatomo\User\Sync(); |
| 148 | $sync->sync_current_users(); |
| 149 | } |
| 150 | } |
| 151 | }), |
| 152 | array('Db.getDatabaseConfig', function (&$config) { |
| 153 | // we don't want to save these and instead detect them on demand. |
| 154 | // for security reasons etc we don't want to duplicate these values |
| 155 | include_once plugin_dir_path(MATOMO_ANALYTICS_FILE ) . 'classes/WpMatomo/Db/WordPress.php'; |
| 156 | }), |
| 157 | array('Tracker.getDatabaseConfig', function (&$configDb) { |
| 158 | // we don't want to save these and instead detect them on demand. |
| 159 | // for security reasons etc we don't want to duplicate these values |
| 160 | include_once plugin_dir_path(MATOMO_ANALYTICS_FILE ) . 'classes/WpMatomo/Db/WordPress.php'; |
| 161 | }), |
| 162 | array('Config.beforeSave', function (&$values) { |
| 163 | // we don't want to save these and instead detect them on demand. |
| 164 | // for security reasons etc we don't want to duplicate these values |
| 165 | unset($values['database']['host']); |
| 166 | unset($values['database']['username']); |
| 167 | unset($values['database']['password']); |
| 168 | unset($values['database']['dbname']); |
| 169 | unset($values['database']['tables_prefix']); |
| 170 | unset($values['database']['charset']); |
| 171 | unset($values['Plugins']); |
| 172 | unset($values['General']['enable_users_admin']); |
| 173 | unset($values['General']['enable_sites_admin']); |
| 174 | unset($values['General']['salt']); |
| 175 | }), |
| 176 | )), |
| 177 | |
| 178 | ); |
| 179 |