updated plugin Connect Matomo version 1.1.5
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
$wpRootDir = isset($wpRootDir)?$wpRootDir:'../../../../';
|
||||
// Get the install directory of WP.
|
||||
// Usefull for immutable WP install, like : https://github.com/zorglube/clever-wordpress OR https://github.com/CleverCloud/wordpress-bedrock-example where WP core and Plugins are in separate directories
|
||||
$wpRootDir = getenv('WP_MATOMO_WP_ROOT_DIR');
|
||||
$wpRootDir = !empty($wpRootDir)?$wpRootDir:'../../../../';
|
||||
require ($wpRootDir.'wp-load.php');
|
||||
|
||||
require_once ('../classes/WP_Piwik/Settings.php');
|
||||
@ -11,29 +14,31 @@ $settings = new WP_Piwik\Settings ( $logger );
|
||||
|
||||
$protocol = (isset ( $_SERVER ['HTTPS'] ) && $_SERVER ['HTTPS'] != 'off') ? 'https' : 'http';
|
||||
|
||||
switch ($settings->getGlobalOption ( 'piwik_mode' )) {
|
||||
switch ($settings->get_global_option ( 'piwik_mode' )) {
|
||||
case 'php' :
|
||||
$PIWIK_URL = $settings->getGlobalOption ( 'proxy_url' );
|
||||
$PIWIK_URL = $settings->get_global_option ( 'proxy_url' );
|
||||
break;
|
||||
case 'cloud' :
|
||||
$PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'piwik_user' ) . '.innocraft.cloud/';
|
||||
$PIWIK_URL = 'https://' . $settings->get_global_option ( 'piwik_user' ) . '.innocraft.cloud/';
|
||||
break;
|
||||
case 'cloud-matomo' :
|
||||
$PIWIK_URL = 'https://' . $settings->getGlobalOption ( 'matomo_user' ) . '.matomo.cloud/';
|
||||
$PIWIK_URL = 'https://' . $settings->get_global_option ( 'matomo_user' ) . '.matomo.cloud/';
|
||||
break;
|
||||
default :
|
||||
$PIWIK_URL = $settings->getGlobalOption ( 'piwik_url' );
|
||||
$PIWIK_URL = $settings->get_global_option ( 'piwik_url' );
|
||||
break;
|
||||
}
|
||||
|
||||
if (substr ( $PIWIK_URL, 0, 2 ) == '//')
|
||||
if ( substr ( $PIWIK_URL, 0, 2 ) == '//' ) {
|
||||
$PIWIK_URL = $protocol . ':' . $PIWIK_URL;
|
||||
}
|
||||
|
||||
$TOKEN_AUTH = $settings->getGlobalOption ( 'piwik_token' );
|
||||
$timeout = $settings->getGlobalOption ( 'connection_timeout' );
|
||||
$TOKEN_AUTH = $settings->get_global_option ( 'piwik_token' );
|
||||
$timeout = $settings->get_global_option ( 'connection_timeout' );
|
||||
$useCurl = (
|
||||
(function_exists('curl_init') && ini_get('allow_url_fopen') && $settings->getGlobalOption('http_connection') == 'curl') || (function_exists('curl_init') && !ini_get('allow_url_fopen'))
|
||||
(function_exists('curl_init') && ini_get('allow_url_fopen') && $settings->get_global_option('http_connection') == 'curl') || (function_exists('curl_init') && !ini_get('allow_url_fopen'))
|
||||
);
|
||||
|
||||
$settings->getGlobalOption ( 'http_connection' );
|
||||
$settings->get_global_option ( 'http_connection' );
|
||||
|
||||
ini_set ( 'display_errors', 0 );
|
||||
ini_set ( 'display_errors', 0 );
|
||||
|
||||
@ -126,6 +126,10 @@ if (strpos($path, 'piwik.php') === 0 || strpos($path, 'matomo.php') === 0) {
|
||||
'cip' => getVisitIp(),
|
||||
'token_auth' => $TOKEN_AUTH,
|
||||
);
|
||||
|
||||
if (!isset($_GET['token_auth']) && !isset($_POST['token_auth'])) {
|
||||
sanitizeTrackingOverrideParams($_GET);
|
||||
}
|
||||
}
|
||||
|
||||
$url = $MATOMO_URL . $path;
|
||||
@ -293,8 +297,14 @@ function getHttpContentAndStatus($url, $timeout, $user_agent)
|
||||
// if there's POST data, send our proxy request as a POST
|
||||
if (!empty($_POST)) {
|
||||
$postBody = file_get_contents("php://input");
|
||||
if (!isset($_GET['token_auth']) && !isset($_POST['token_auth'])) {
|
||||
$didSanitizePostParams = sanitizeTrackingOverrideParams($_POST);
|
||||
if ($didSanitizePostParams) {
|
||||
$postBody = http_build_query($_POST);
|
||||
}
|
||||
}
|
||||
|
||||
$stream_options['http']['method'] = 'POST';
|
||||
$stream_options['http']['method'] = 'POST';
|
||||
$stream_options['http']['header'][] = "Content-type: application/x-www-form-urlencoded";
|
||||
$stream_options['http']['header'][] = "Content-Length: " . strlen($postBody);
|
||||
$stream_options['http']['content'] = $postBody;
|
||||
@ -365,6 +375,20 @@ function getHttpContentAndStatus($url, $timeout, $user_agent)
|
||||
|
||||
}
|
||||
|
||||
function sanitizeTrackingOverrideParams(&$params)
|
||||
{
|
||||
$didSanitizeParams = false;
|
||||
$queryParamsToUnset = ['cdt', 'country', 'region', 'city', 'lat', 'long', 'cip'];
|
||||
foreach ($queryParamsToUnset as $queryParamToUnset) {
|
||||
if (isset($params[$queryParamToUnset])) {
|
||||
unset($params[$queryParamToUnset]);
|
||||
$didSanitizeParams = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $didSanitizeParams;
|
||||
}
|
||||
|
||||
function sendHeader($header, $replace = true)
|
||||
{
|
||||
headers_sent() || header($header, $replace);
|
||||
|
||||
Reference in New Issue
Block a user