HEX
Server: Apache
System: Linux server11 5.10.0-33-amd64 #1 SMP Debian 5.10.226-1 (2024-10-03) x86_64
User: web78 (5081)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/clients/client1/web78/web/wp-content/plugins/loco-translate/src/api/Providers.php
<?php
/**
 * Third party API helpers
 */
abstract class Loco_api_Providers {


    /**
     * Export API credentials for all supported APIs
     * @return array[]
     */
    public static function export(){
        $apis = [];
        foreach( self::builtin() as $a ){
            $hook = 'loco_api_provider_'.$a['id'];
            $apis[] = apply_filters($hook, $a );
        }
        return apply_filters( 'loco_api_providers', $apis );
    }
    
    
    /**
     * @return array[]
     */
    public static function builtin(){
        $settings = Loco_data_Settings::get();
        return  [
             [
                'id' => 'deepl',
                'name' => 'DeepL Translator',
                'key' => $settings->offsetGet('deepl_api_key'),
                'url' => 'https://www.deepl.com/translator',
            ],[
                'id' => 'google',
                'name' => 'Google Translate',
                'key' => $settings->offsetGet('google_api_key'),
                'url' => 'https://translate.google.com/',
            ],[
                'id' => 'microsoft',
                'name' => 'Microsoft Translator',
                'key' => $settings->offsetGet('microsoft_api_key'),
                'region' => $settings->offsetGet('microsoft_api_region'),
                'url' => 'https://aka.ms/MicrosoftTranslatorAttribution',
            ],[
                'id' => 'lecto',
                'name' => 'Lecto AI',
                'key' => $settings->offsetGet('lecto_api_key'),
                'url' => 'https://lecto.ai/?ref=loco',
            ],
        ];
    }
    
    
    /**
     * Get only configured APIs, and sort them fairly
     * @return array[]
     */
    public static function configured(){
        return self::sort( array_filter( self::export(), [__CLASS__,'filterConfigured'] ) );
    }


    /**
     * @internal
     * @param $api string[]
     * @return bool
     */
    private static function filterConfigured( array $api ){
        return array_key_exists('key',$api) && is_string($api['key']) && '' !== $api['key'];
    }


    /**
     * @internal
     * @param string[] $a
     * @param string[] $b
     * @return int
     */
    private static function compareNames( array $a, array $b ){
        return strcasecmp($a['name'],$b['name']);
    }
    
    
    /**
     * Sort providers alphabetically
     * @param array[] $apis
     * @return array
     */
    public static function sort( array $apis ){
        usort( $apis, [__CLASS__,'compareNames'] );
        return $apis;
    }

}