Exemplo n.º 1
0
        PhpValue /*object|array|WP_Error*/ PluginsApi(PhpValue result, string action, object args)
        {
            var arr = (PhpArray)PhpValue.FromClass(args);
            var log = NuGet.Common.NullLogger.Instance;

            switch (action)
            {
            case "query_plugins":

                var results = SearchFeed(arr, WpPluginPackageType, out var page, out var per_page, out var totalHits).ToList();

                return(PhpValue.FromClass(new QueryPluginsResult
                {
                    info = new PhpArray()
                    {
                        { "page", page },
                        { "pages", (totalHits / per_page) + ((totalHits % per_page) == 0 ? 0 : 1) },
                        { "results", results.Count },
                    },
                    plugins = new PhpArray(results.Select(_ => new PluginResult(_))),
                }));

            case "plugin_information":

                var versions = RegistrationResourceV3.GetPackageMetadata(PluginResult.SlugToId(arr["slug"].ToString()), true, true, log, CancellationToken.None)
                               .Result
                               .Select(PackageSearchMetadataFromJObject);
                var p = versions.LastOrDefault();

                //var p = PackageMetadataResource.GetMetadataAsync(new PackageIdentity(arr["slug"].ToString(), new NuGet.Versioning.NuGetVersion("")), log, CancellationToken.None).Result;
                if (p != null)
                {
                    var packageBaseAddress = ServiceIndexResourceV3.GetServiceEntryUri(ServiceTypes.PackageBaseAddress)?.AbsoluteUri;
                    var id      = p.Identity.Id.ToLowerInvariant();
                    var version = p.Identity.Version.ToNormalizedString().ToLowerInvariant();
                    var url     = $"{packageBaseAddress}/{id}/{version}/{id}.{version}.nupkg";

                    return(PhpValue.FromClass(new PluginResult(p)
                    {
                        download_link = url
                    }));
                }
                else
                {
                    return(PhpValue.Null);
                }

            case "hot_tags":
            case "hot_categories":
                // // stdClass { "name" => array("name", "slug", "count") }
                // return PhpValue.FromClass(
                //     new PhpArray()
                //     {

                //     }.AsStdClass()
                // );
                return(false);    // -> use regular WP API

            default:
                throw new ArgumentException(nameof(action));
            }
        }