Файловый менеджер - Редактировать - /home/infrafs/INFRABIKEIT/wp-content/plugins/analyst.zip
Назад
PK Rd2\�'{X index.phpnu �[��� <?php // Silence PK Rd2\��� � autoload.phpnu �[��� <?php require_once __DIR__ . '/src/helpers.php'; require_once __DIR__ . '/src/Contracts/HttpClientContract.php'; require_once __DIR__ . '/src/Contracts/RequestContract.php'; require_once __DIR__ . '/src/Contracts/RequestorContract.php'; require_once __DIR__ . '/src/Contracts/TrackerContract.php'; require_once __DIR__ . '/src/Contracts/CacheContract.php'; require_once __DIR__ . '/src/Core/AbstractFactory.php'; require_once __DIR__ . '/src/Cache/DatabaseCache.php'; require_once __DIR__ . '/src/Account/Account.php'; require_once __DIR__ . '/src/Account/AccountData.php'; require_once __DIR__ . '/src/Account/AccountDataFactory.php'; require_once __DIR__ . '/src/Contracts/AnalystContract.php'; require_once __DIR__ . '/src/Http/Requests/AbstractLoggerRequest.php'; require_once __DIR__ . '/src/Http/Requests/ActivateRequest.php'; require_once __DIR__ . '/src/Http/Requests/DeactivateRequest.php'; require_once __DIR__ . '/src/Http/Requests/InstallRequest.php'; require_once __DIR__ . '/src/Http/Requests/OptInRequest.php'; require_once __DIR__ . '/src/Http/Requests/OptOutRequest.php'; require_once __DIR__ . '/src/Http/Requests/UninstallRequest.php'; require_once __DIR__ . '/src/Http/CurlHttpClient.php'; require_once __DIR__ . '/src/Http/DummyHttpClient.php'; require_once __DIR__ . '/src/Http/WordPressHttpClient.php'; require_once __DIR__ . '/src/Notices/Notice.php'; require_once __DIR__ . '/src/Notices/NoticeFactory.php'; require_once __DIR__ . '/src/Analyst.php'; require_once __DIR__ . '/src/ApiRequestor.php'; require_once __DIR__ . '/src/ApiResponse.php'; require_once __DIR__ . '/src/Collector.php'; require_once __DIR__ . '/src/Mutator.php'; PK Rd2\r�|� � main.phpnu �[��� <?php require_once 'sdk_resolver.php'; if (!function_exists('analyst_init')) { /** * Initialize analyst * * @param array $options */ function analyst_init ($options) { // Try resolve latest supported SDK // In case resolving is failed exit the execution try { analyst_resolve_sdk($options['base-dir']); } catch (Exception $exception) { // error_log('[ANALYST] Cannot resolve any supported SDK'); return; } try { global /** @var Analyst\Analyst $analyst */ $analyst; // Set global instance of analyst if (!$analyst) { $analyst = Analyst\Analyst::getInstance(); } $analyst->registerAccount(new Account\Account($options['client-id'], $options['client-secret'], $options['base-dir'])); } catch (Exception $e) { // error_log('Analyst SDK receive an error: [' . $e->getMessage() . '] Please contact our support at support@analyst.com'); } } } PK Rd2\ ��� � sdk_resolver.phpnu �[��� <?php if (!function_exists('analyst_resolve_sdk')) { /** * Resolve supported sdk versions and load latest supported one * also bootstrap sdk with autoloader * * @since 1.1.3 * * @param null $thisPluginPath * @return void * @throws Exception */ function analyst_resolve_sdk($thisPluginPath = null) { static $loaded = false; // Exit if we already resolved SDK if ($loaded) return; $plugins = get_option('active_plugins'); if ($thisPluginPath) { array_push($plugins, plugin_basename($thisPluginPath)); } $pluginsFolder = WP_PLUGIN_DIR; $possibleSDKs = array_map(function ($path) use ($pluginsFolder) { $sdkFolder = sprintf('%s/%s/analyst/', $pluginsFolder, dirname($path)); $sdkFolder = str_replace('\\', '/', $sdkFolder); $versionPath = $sdkFolder . 'version.php'; if (file_exists($versionPath)) { return require $versionPath; } return false; }, $plugins); global $wp_version; // Filter out plugins which has no SDK $SDKs = array_filter($possibleSDKs, function ($s) {return is_array($s);}); // Filter SDKs which is supported by PHP and WP $supported = array_values(array_filter($SDKs, function ($sdk) use($wp_version) { $phpSupported = version_compare(PHP_VERSION, $sdk['php']) >= 0; $wpSupported = version_compare($wp_version, $sdk['wp']) >= 0; return $phpSupported && $wpSupported; })); // Sort SDK by version in descending order uasort($supported, function ($x, $y) { return version_compare($y['sdk'], $x['sdk']); }); // Reset sorted values keys $supported = array_values($supported); if (!isset($supported[0])) { throw new Exception('There is no SDK which is support current PHP version and WP version'); } // Autoload files for supported SDK $autoloaderPath = str_replace( '\\', '/', sprintf('%s/autoload.php', $supported[0]['path']) ); require_once $autoloaderPath; $loaded = true; } } PK Rd2\d���J J src/Analyst.phpnu �[��� <?php namespace Analyst; use Account\Account; use Account\AccountDataFactory; use Analyst\Contracts\AnalystContract; use Analyst\Contracts\RequestorContract; class Analyst implements AnalystContract { /** * All plugin's accounts * * @var array */ protected $accounts = array(); /** * @var Mutator */ protected $mutator; /** * @var AccountDataFactory */ protected $accountDataFactory; /** * Base url to api * * @var string */ protected $apiBase = 'https://feedback.sellcodes.com/api/v1'; /** * @var Collector */ protected $collector; /** * Singleton instance * * @var static */ protected static $instance; /** * Get instance of analyst * * @return Analyst * @throws \Exception */ public static function getInstance() { if (!static::$instance) { static::$instance = new Analyst(); } return static::$instance; } protected function __construct() { $this->mutator = new Mutator(); $this->accountDataFactory = AccountDataFactory::instance(); $this->mutator->initialize(); $this->collector = new Collector($this); $this->initialize(); } /** * Initialize rest of application */ public function initialize() { add_action('init', function () { $this->collector->loadCurrentUser(); }); } /** * Register new account * * @param Account $account * @return Analyst * @throws \Exception */ public function registerAccount($account) { // Stop propagation when account is already registered if ($this->isAccountRegistered($account)) { return $this; } // Resolve account data from factory $accountData = $this->accountDataFactory->resolvePluginAccountData($account); $account->setData($accountData); $account->setRequestor( $this->resolveRequestorForAccount($account) ); $account->setCollector($this->collector); $account->registerHooks(); $this->accounts[$account->getId()] = $account; return $this; } /** * Must return version of analyst * * @return string */ public static function version() { $version = require __DIR__ . '/../version.php'; return $version['sdk']; } /** * Is this account registered * * @param Account $account * @return bool */ protected function isAccountRegistered($account) { return isset($this->accounts[$account->getId()]); } /** * Resolves requestor for account * * @param Account $account * @return RequestorContract * @throws \Exception */ protected function resolveRequestorForAccount(Account $account) { $requestor = new ApiRequestor($account->getId(), $account->getClientSecret(), $this->apiBase); // Set SDK version $requestor->setDefaultHeader( 'x-analyst-client-user-agent', sprintf('Analyst/%s', $this->version()) ); return $requestor; } /** * @return string */ public function getApiBase() { return $this->apiBase; } } PK Rd2\�l^ src/ApiRequestor.phpnu �[��� <?php namespace Analyst; use Exception; use Analyst\Contracts\HttpClientContract; use Analyst\Contracts\RequestorContract; class ApiRequestor implements RequestorContract { /** * Supported http client * * @var HttpClientContract */ protected $httpClient; /** * @var string */ protected $clientId; /** * @var string */ protected $clientSecret; /** * @var string */ protected $apiBase; /** * Default headers to be sent * * @var array */ protected $defaultHeaders = [ 'accept' => 'application/json', 'content-type' => 'application/json' ]; /** * Prioritized http clients * * @var array */ protected $availableClients = [ 'Analyst\Http\WordPressHttpClient', 'Analyst\Http\CurlHttpClient', 'Analyst\Http\DummyHttpClient', ]; /** * ApiRequestor constructor. * @param $id * @param $secret * @param $apiBase * @throws \Exception */ public function __construct($id, $secret, $apiBase) { $this->clientId = $id; $this->clientSecret = $secret; $this->setApiBase($apiBase); $this->httpClient = $this->resolveHttpClient(); } /** * Set api base url * * @param $url */ public function setApiBase($url) { $this->apiBase = $url; } /** * Get request * * @param $url * @param array $headers * @return mixed */ public function get($url, $headers = []) { return $this->request('GET', $url, null, $headers); } /** * Post request * * @param $url * @param $body * @param array $headers * @return mixed */ public function post($url, $body = [], $headers = []) { return $this->request('POST', $url, $body, $headers); } /** * Put request * * @param $url * @param $body * @param array $headers * @return mixed */ public function put($url, $body = [], $headers = []) { return $this->request('PUT', $url, $body, $headers); } /** * Delete request * * @param $url * @param array $headers * @return mixed */ public function delete($url, $headers = []) { return $this->request('DELETE', $url, null, $headers); } /** * Make request to api * * @param $method * @param $url * @param array $body * @param array $headers * @return mixed */ protected function request($method, $url, $body = [], $headers = []) { $fullUrl = $this->resolveFullUrl($url); $date = date('r', time()); $headers['date'] = $date; $headers['signature'] = $this->resolveSignature($this->clientSecret, $method, $fullUrl, $body, $date); // Lowercase header names $headers = $this->prepareHeaders( array_merge($headers, $this->defaultHeaders) ); $response = $this->httpClient->request($method, $fullUrl, $body, $headers); // TODO: Check response code and take actions return $response; } /** * Set one default header * * @param $header * @param $value */ public function setDefaultHeader($header, $value) { $this->defaultHeaders[ $this->resolveValidHeaderName($header) ] = $value; } /** * Resolves supported http client * * @return HttpClientContract * @throws Exception */ protected function resolveHttpClient() { $clients = array_filter($this->availableClients, $this->guessClientSupportEnvironment()); if (!isset($clients[0])) { throw new Exception('There is no http client which this application can support'); } // Instantiate first supported http client return new $clients[0]; } /** * This will filter out clients which is not supported * by the current environment * * @return \Closure */ protected function guessClientSupportEnvironment() { return function ($client) { return forward_static_call([$client, 'hasSupport']); }; } /** * Resolves valid header name * * @param $headerName * @return string */ private function resolveValidHeaderName($headerName) { return strtolower($headerName); } /** * Lowercase header names * * @param $headers * @return array */ private function prepareHeaders($headers) { return array_change_key_case($headers, CASE_LOWER); } /** * Sign request * * @param $key * @param $method * @param $url * @param $body * @param $date * * @return false|string */ private function resolveSignature($key, $method, $url, $body, $date) { $string = implode('\n', [$method, $url, md5(json_encode($body)), $date]); $contentSecret = hash_hmac('sha256', $string, $key); return sprintf('%s:%s', $this->clientId, $contentSecret); } /** * Compose full url * * @param $url * @return string */ private function resolveFullUrl($url) { return sprintf('%s/%s', $this->apiBase, trim($url, '/')); } } PK Rd2\Y�� � src/Http/WordPressHttpClient.phpnu �[��� <?php namespace Analyst\Http; use WP_Error; use Analyst\ApiResponse; use Analyst\Contracts\HttpClientContract; use Requests_Utility_CaseInsensitiveDictionary; class WordPressHttpClient implements HttpClientContract { /** * Make an http request * * @param $method * @param $url * @param $body * @param $headers * @return ApiResponse */ public function request($method, $url, $body, $headers) { $options = [ 'body' => json_encode($body), 'headers' => $headers, 'method' => $method, 'timeout' => 30, ]; $response = wp_remote_request($url, $options); $body = []; $responseHeaders = []; if ($response instanceof WP_Error) { $code = $response->get_error_code(); } else { /** @var Requests_Utility_CaseInsensitiveDictionary $headers */ $responseHeaders = $response['headers']->getAll(); $body = json_decode($response['body'], true); $code = $response['response']['code']; } return new ApiResponse( $body, $code, $responseHeaders ); } /** * Must return `true` if client is supported * * @return bool */ public static function hasSupport() { return function_exists('wp_remote_request'); } } PK Rd2\(�n= = src/Http/CurlHttpClient.phpnu �[��� <?php namespace Analyst\Http; use Analyst\ApiResponse; use Analyst\Contracts\HttpClientContract; class CurlHttpClient implements HttpClientContract { /** * Make an http request * * @param $method * @param $url * @param array $body * @param $headers * @return mixed */ public function request($method, $url, $body, $headers) { $method = strtoupper($method); $options = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => $this->prepareRequestHeaders($headers), CURLOPT_CUSTOMREQUEST => $method, CURLOPT_FAILONERROR => true, CURLOPT_HEADER => true, CURLOPT_TIMEOUT => 30, ]; if ($method === 'POST') { $options[CURLOPT_POST] = 1; $options[CURLOPT_POSTFIELDS] = json_encode($body); } $curl = curl_init(); curl_setopt_array($curl, $options); $response = curl_exec($curl); list($rawHeaders, $rawBody) = explode("\r\n\r\n", $response, 2); $info = curl_getinfo($curl); curl_close($curl); $responseHeaders = $this->resolveResponseHeaders($rawHeaders); $responseBody = json_decode($rawBody, true); return new ApiResponse($responseBody, $info['http_code'], $responseHeaders); } /** * Must return `true` if client is supported * * @return bool */ public static function hasSupport() { return function_exists('curl_version'); } /** * Modify request headers from key value pair * to vector array * * @param array $headers * @return array */ protected function prepareRequestHeaders ($headers) { return array_map(function ($key, $value) { return sprintf('%s:%s', $key, $value); }, array_keys($headers), $headers); } /** * Resolve raw response headers as * associative array * * @param $rawHeaders * @return array */ private function resolveResponseHeaders($rawHeaders) { $headers = []; foreach (explode("\r\n", $rawHeaders) as $i => $line) { $parts = explode(': ', $line); if (count($parts) === 1) { continue; } $headers[$parts[0]] = $parts[1]; } return $headers; } } PK Rd2\>7�� � $ src/Http/Requests/InstallRequest.phpnu �[��� <?php namespace Analyst\Http\Requests; use Analyst\ApiResponse; use Analyst\Collector; use Analyst\Contracts\RequestorContract; /** * Class InstallRequest * * @since 0.9.4 */ class InstallRequest extends AbstractLoggerRequest { /** * Execute the request * @param RequestorContract $requestor * @return ApiResponse */ public function execute(RequestorContract $requestor) { return $requestor->post('logger/install', $this->toArray()); } /** * Make request instance * * @param Collector $collector * @param $pluginId * @param $path * @return static */ public static function make(Collector $collector, $pluginId, $path) { return new static($collector, $pluginId, $path); } } PK Rd2\:5�� + src/Http/Requests/AbstractLoggerRequest.phpnu �[��� <?php namespace Analyst\Http\Requests; use Analyst\ApiResponse; use Analyst\Collector; use Analyst\Contracts\RequestContract; use Analyst\Contracts\RequestorContract; abstract class AbstractLoggerRequest implements RequestContract { /** * @var Collector */ protected $collector; /** * @var integer */ protected $id; /** * @var string */ protected $path; public function __construct(Collector $collector, $pluginId, $path) { $this->collector = $collector; $this->id = $pluginId; $this->path = $path; } /** * Cast request data to array * * @return array */ public function toArray() { return [ 'plugin_id' => $this->id, 'php_version' => $this->collector->getPHPVersion(), 'wp_version' => $this->collector->getWordPressVersion(), 'plugin_version' => $this->collector->getPluginVersion($this->path), 'url' => $this->collector->getSiteUrl(), 'sdk_version' => $this->collector->getSDKVersion(), 'ip' => $this->collector->getServerIp(), 'mysql_version' => $this->collector->getMysqlVersion(), 'locale' => $this->collector->getSiteLanguage(), 'current_theme' => $this->collector->getCurrentThemeName(), 'active_plugins_list' => implode(', ', $this->collector->getActivePluginsList()), 'email' => $this->collector->getGeneralEmailAddress(), 'name' => $this->collector->getCurrentUserName() ]; } /** * Execute the request * @param RequestorContract $requestor * @return ApiResponse */ public abstract function execute(RequestorContract $requestor); } PK Rd2\�{fS4 4 "