modified file upgrade-temp-backup

This commit is contained in:
2026-07-28 15:05:31 +00:00
committed by Gitium
parent 64be23dffb
commit dd0a8b69b1
486 changed files with 123520 additions and 0 deletions

View File

@ -0,0 +1,94 @@
<?php
namespace WP_Piwik\Request;
class Php extends \WP_Piwik\Request {
/**
* @var mixed
*/
private static $piwik_environment = false;
protected function request( $id ) {
$count = 0;
$url = self::$settings->get_global_option( 'piwik_url' );
foreach ( self::$requests as $request_id => $config ) {
if ( ! isset( self::$results[ $request_id ] ) ) {
if ( '' !== self::$settings->get_global_option( 'filter_limit' ) && is_numeric( self::$settings->get_global_option( 'filter_limit' ) ) ) {
$config['parameter']['filter_limit'] = self::$settings->get_global_option( 'filter_limit' );
}
$params = $this->get_url_params( $config );
$params['module'] = 'API';
$params['format'] = 'json';
$map[ $count ] = $request_id;
$result = $this->call( $id, $url, $params );
self::$results[ $map[ $count ] ] = $result;
++$count;
}
}
}
private function call( $id, $url, $params ) {
if ( ! defined( 'PIWIK_INCLUDE_PATH' ) ) {
return false;
}
if ( PIWIK_INCLUDE_PATH === false ) {
return array(
'result' => 'error',
'message' => __( 'Could not resolve', 'wp-piwik' ) . ' &quot;' . htmlentities( self::$settings->get_global_option( 'piwik_path' ) ) . '&quot;: ' . __( 'realpath() returns false', 'wp-piwik' ) . '.',
);
}
if ( file_exists( PIWIK_INCLUDE_PATH . '/index.php' ) ) {
require_once PIWIK_INCLUDE_PATH . '/index.php';
}
if ( file_exists( PIWIK_INCLUDE_PATH . '/core/API/Request.php' ) ) {
require_once PIWIK_INCLUDE_PATH . '/core/API/Request.php';
}
if ( class_exists( '\Piwik\Application\Environment' ) && ! self::$piwik_environment ) {
// Piwik 2.14.* compatibility fix
self::$piwik_environment = new \Piwik\Application\Environment( null );
self::$piwik_environment->init();
}
if ( class_exists( 'Piwik\FrontController' ) ) {
\Piwik\FrontController::getInstance()->init();
} else {
return array(
'result' => 'error',
'message' => __( 'Class Piwik\FrontController does not exists.', 'wp-piwik' ),
);
}
if ( class_exists( 'Piwik\API\Request' ) ) {
$params['token_auth'] = self::$settings->get_global_option( 'piwik_token' );
$request = new \Piwik\API\Request( $params );
} else {
return array(
'result' => 'error',
'message' => __( 'Class Piwik\API\Request does not exists.', 'wp-piwik' ),
);
}
$result = $request->process();
if ( ! headers_sent() ) {
header( 'Content-Type: text/html', true );
}
$result = $this->unserialize( $result );
if ( $GLOBALS ['wp-piwik_debug'] ) {
self::$debug[ $id ] = array( $params . '&token_auth=...' );
}
return $result;
}
public function reset() {
if (
class_exists( '\Piwik\Application\Environment' )
&& self::$piwik_environment instanceof \Piwik\Application\Environment
) {
self::$piwik_environment->destroy();
}
if ( class_exists( 'Piwik\FrontController' ) ) {
\Piwik\FrontController::unsetInstance();
}
parent::reset();
}
}

View File

@ -0,0 +1,126 @@
<?php
namespace WP_Piwik\Request;
/**
* TODO: switch to wp_remote_get
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_close
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_getinfo
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_error
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_init
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_setopt
* phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_exec
* phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
*/
class Rest extends \WP_Piwik\Request {
protected function request( $id ) {
$count = 0;
$url = self::$settings->get_matomo_url();
$params = 'module=API&method=API.getBulkRequest&format=json';
$filter_limit = self::$settings->get_global_option( 'filter_limit' );
if (
$filter_limit > 0
&& is_numeric( self::$settings->get_global_option( 'filter_limit' ) )
) {
$params .= '&filter_limit=' . self::$settings->get_global_option( 'filter_limit' );
}
foreach ( self::$requests as $request_id => $config ) {
if ( ! isset( self::$results[ $request_id ] ) ) {
$params .= '&urls[' . $count . ']=' . rawurlencode( $this->build_url( $config ) );
$map[ $count ] = $request_id;
++$count;
}
}
$use_curl = (
function_exists( 'curl_init' )
&& ini_get( 'allow_url_fopen' )
&& 'curl' === self::$settings->get_global_option( 'http_connection' )
) || (
function_exists( 'curl_init' )
&& ! ini_get( 'allow_url_fopen' )
);
$results = $use_curl ? $this->curl( $id, $url, $params ) : $this->fopen( $id, $url, $params );
if ( is_array( $results ) ) {
foreach ( $results as $num => $result ) {
if ( isset( $map[ $num ] ) ) {
self::$results[ $map[ $num ] ] = $result;
}
}
}
}
private function curl( $id, $url, $params ) {
if ( 'post' === self::$settings->get_global_option( 'http_method' ) ) {
$c = curl_init( $url );
curl_setopt( $c, CURLOPT_POST, 1 );
curl_setopt( $c, CURLOPT_POSTFIELDS, $params . '&token_auth=' . self::$settings->get_global_option( 'piwik_token' ) );
} else {
$c = curl_init( $url . '?' . $params . '&token_auth=' . self::$settings->get_global_option( 'piwik_token' ) );
}
curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, ! self::$settings->get_global_option( 'disable_ssl_verify' ) );
curl_setopt( $c, CURLOPT_SSL_VERIFYHOST, ! self::$settings->get_global_option( 'disable_ssl_verify_host' ) ? 2 : 0 );
curl_setopt( $c, CURLOPT_USERAGENT, 'php' === self::$settings->get_global_option( 'piwik_useragent' ) ? ini_get( 'user_agent' ) : self::$settings->get_global_option( 'piwik_useragent_string' ) );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $c, CURLOPT_HEADER, $GLOBALS ['wp-piwik_debug'] );
curl_setopt( $c, CURLOPT_TIMEOUT, self::$settings->get_global_option( 'connection_timeout' ) );
$http_proxy_class = new \WP_HTTP_Proxy();
if ( $http_proxy_class->is_enabled() && $http_proxy_class->send_through_proxy( $url ) ) {
curl_setopt( $c, CURLOPT_PROXY, $http_proxy_class->host() );
curl_setopt( $c, CURLOPT_PROXYPORT, $http_proxy_class->port() );
if ( $http_proxy_class->use_authentication() ) {
curl_setopt( $c, CURLOPT_PROXYUSERPWD, $http_proxy_class->username() . ':' . $http_proxy_class->password() );
}
}
$result = curl_exec( $c );
self::$last_error = curl_error( $c );
if ( $GLOBALS ['wp-piwik_debug'] ) {
$header_size = curl_getinfo( $c, CURLINFO_HEADER_SIZE );
$header = substr( $result, 0, $header_size );
$body = substr( $result, $header_size );
$result = $this->unserialize( $body );
self::$debug[ $id ] = array( $header, $url . '?' . $params . '&token_auth=...' );
} else {
$result = $this->unserialize( $result );
}
if ( version_compare( PHP_VERSION, '8', '<' ) ) {
curl_close( $c );
}
return $result;
}
private function fopen( $id, $url, $params ) {
$context_definition = array(
'http' => array(
'timeout' => self::$settings->get_global_option( 'connection_timeout' ),
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
),
);
$context_definition['ssl'] = array();
if ( self::$settings->get_global_option( 'disable_ssl_verify' ) ) {
$context_definition['ssl'] = array(
'allow_self_signed' => true,
'verify_peer' => false,
);
}
if ( self::$settings->get_global_option( 'disable_ssl_verify_host' ) ) {
$context_definition['ssl']['verify_peer_name'] = false;
}
if ( self::$settings->get_global_option( 'http_method' ) === 'post' ) {
$full_url = $url;
$context_definition['http']['method'] = 'POST';
$context_definition['http']['content'] = $params . '&token_auth=' . self::$settings->get_global_option( 'piwik_token' );
} else {
$full_url = $url . '?' . $params . '&token_auth=' . self::$settings->get_global_option( 'piwik_token' );
}
$context = stream_context_create( $context_definition );
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$result = $this->unserialize( @file_get_contents( $full_url, false, $context ) );
if ( $GLOBALS ['wp-piwik_debug'] ) {
self::$debug[ $id ] = array( get_headers( $full_url, 1 ), $url . '?' . $params . '&token_auth=...' );
}
return $result;
}
}