示例#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":
                return(PhpValue.Null);

            default:
                throw new ArgumentException(nameof(action));
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="override"></param>
        /// <param name="action"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        PhpValue /*object|array|WP_Error*/ ThemesApi(PhpValue /*false|object|array*/ @override, string action, object args)
        {
            var arr = (PhpArray)PhpValue.FromClass(args);
            var log = NuGet.Common.NullLogger.Instance;

            if (action == "query_themes")
            {
                var results = SearchFeed(arr, WpThemePackageType, out var page, out var per_page, out var totalHits).ToList();

                // return new QueryThemesResult;
                return(PhpValue.FromClass(new QueryThemesResult
                {
                    info = new PhpArray()
                    {
                        { "page", page },
                        { "pages", (totalHits / per_page) + ((totalHits % per_page) == 0 ? 0 : 1) },
                        { "results", results.Count },
                    },
                    themes = new PhpArray(results.Select(_ => new ThemeResult(_))),
                }));
            }
            else if (action == "theme_information")
            {
                var p = RegistrationResourceV3.GetPackageMetadata(PluginResult.SlugToId(arr["slug"].ToString()), true, true, log, CancellationToken.None)
                        .Result
                        .Select(PackageSearchMetadataFromJObject)
                        .FirstOrDefault();

                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 ThemeResult(p)
                    {
                        download_link = url
                    }));
                }
                else
                {
                    return(PhpValue.Null);
                }
            }

            // default, fallback to WP API:

            return(PhpValue.False);
        }