Viewing File: /usr/local/cpanel/3rdparty/wpinstaller/src/WpDownloader/WpApi.php

<?php
namespace WpDownloader;

class WpApi extends HttpApi
{
    public static $baseUrl = 'https://api.wordpress.org';
    protected static $logFile = 'wp_api';

    public static function getFileChecksumsForVersion($version)
    {
        $response = self::apiRequest('/core/checksums/1.0', [
            'version' => $version,
            'locale'  => 'en_US'
        ]);

        if (empty($response['checksums'])) {
            throw new \Exception("Failed to retrieve checksums from API. Response was:".print_r($response, 1));
        }

        return $response['checksums'];
    }

    public static function getAllVersions()
    {
        $response = self::apiRequest('/core/version-check/1.7/');

        if (empty($response['offers'])) {
            throw new \Exception("Failed to retrieve version data from API. Response was:".print_r($response, 1));
        }

        return $response['offers'];
    }

    public static function getLatestVersion()
    {
        $all = self::getAllVersions();

        return array_shift($all);
    }

    public static function getLatestVersionNumber()
    {
        $latest = self::getLatestVersion();

        return $latest['version'];
    }

    private static function _getPluginData($pluginSlug)
    {
        $slugUrl = urlencode($pluginSlug);
        $response = self::apiRequest("/plugins/info/1.0/{$slugUrl}.json");

        if (empty($response['version'])) {
            throw new \Exception("Failed to retrieve version data from API for plugin {$pluginSlug}. Response was:".print_r($response, 1));
        }

        return $response;
    }

    public static function getPluginData($pluginSlug)
    {
        static $cache = [];

        if (!isset($cache[$pluginSlug])) {
            $cache[$pluginSlug] = self::_getPluginData($pluginSlug);
        }

        return $cache[$pluginSlug];
    }

    public static function getLatestPluginVersionNumber($pluginSlug)
    {
        $data = self::getPluginData($pluginSlug);

        return $data['version'];
    }
}
Back to Directory File Manager