<?php 
/**
 * Plugin Name: Api Reference (Matomo Plugin)
 * Plugin URI: http://plugins.matomo.org/ApiReference
 * Description: Modern interactive API documentation for Matomo based on OpenAPI (Swagger). Explore endpoints, parameters, and responses directly in your browser. 
 * Author: Matomo
 * Author URI: https://matomo.org
 * Version: 5.0.7
 */
?><?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\ApiReference;

 
if (defined( 'ABSPATH')
&& function_exists('add_action')) {
    $path = '/matomo/app/core/Plugin.php';
    if (defined('WP_PLUGIN_DIR') && WP_PLUGIN_DIR && file_exists(WP_PLUGIN_DIR . $path)) {
        require_once WP_PLUGIN_DIR . $path;
    } elseif (defined('WPMU_PLUGIN_DIR') && WPMU_PLUGIN_DIR && file_exists(WPMU_PLUGIN_DIR . $path)) {
        require_once WPMU_PLUGIN_DIR . $path;
    } else {
        return;
    }
    add_action('plugins_loaded', function () {
        if (function_exists('matomo_add_plugin')) {
            matomo_add_plugin(__DIR__, __FILE__, true);
        }
    });
}

class ApiReference extends \Piwik\Plugin
{
    public const DEFAULT_SPEC_VERSION = '1.0.0';
    public const OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME = 'oaXmlAttributes';
    public const OA_XML_ATTRIBUTES_DEFAULT_KEY_NAME = 'defaultKeyName';
    public const GENERATED_ANNOTATIONS_PATH = '/tmp/annotations/';
    public const EXAMPLE_RESPONSES_PATH = '/tmp/responses/';
    public const GENERATED_SPECS_PATH = '/tmp/specs/';
    public const AVAILABLE_PROPERTY_TYPES = ['string', 'number', 'integer', 'boolean', 'array', 'object', 'null'];
    public const PLUGIN_BLOCKLIST = ['Billing', 'Cloud', 'ConnectAccounts', 'CDN', 'ProxySite'];

    public function registerEvents()
    {
        return [
            'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
        ];
    }

    public function getClientSideTranslationKeys(&$translationKeys): void
    {
        $translationKeys[] = 'General_API';
        $translationKeys[] = 'CoreHome_LearnMoreFullStop';
        $translationKeys[] = 'ApiReference_LookingForLegacyApiReference';
        $translationKeys[] = 'ApiReference_ReportingApiMoreInformation';
        $translationKeys[] = 'ApiReference_ReportingApiReference';
        $translationKeys[] = 'ApiReference_ReportingApiSummary';
        $translationKeys[] = 'ApiReference_SwaggerPagePluginEmpty';
        $translationKeys[] = 'ApiReference_SwaggerPageConnectToken';
        $translationKeys[] = 'ApiReference_SwaggerPageRequestFailed';
        $translationKeys[] = 'ApiReference_SwaggerPageRemoveToken';
        $translationKeys[] = 'ApiReference_SwaggerPageSpecLoadFailed';
        $translationKeys[] = 'ApiReference_SwaggerPageSpecNotAvailable';
        $translationKeys[] = 'ApiReference_SwaggerPageSearchNoResults';
        $translationKeys[] = 'ApiReference_SwaggerPageSearchPlaceholder';
        $translationKeys[] = 'ApiReference_SwaggerPageTokenConnected';
        $translationKeys[] = 'ApiReference_SwaggerPageTokenConnectedHeading';
        $translationKeys[] = 'ApiReference_UserAuthentication';
        $translationKeys[] = 'ApiReference_UserAuthenticationManageTokens';
        $translationKeys[] = 'ApiReference_UserAuthenticationUsingTokenAuth';
    }

    public function install()
    {
        $config = new Configuration();
        $config->install();
    }

    public function uninstall()
    {
        $config = new Configuration();
        $config->uninstall();
    }
}
