/// <summary>
        /// Processes the GetLinkMetadata action.
        /// </summary>
        /// <param name="linkUrl">The link URL.</param>
        public GetLinkMetadataActionResult ProcessAction(string linkUrl)
        {
            if (!VirtualContext.IsPreviewLinkInitialized)
            {
                return(new GetLinkMetadataActionResult(HttpStatusCode.Forbidden, statusCodeMessage: "The request is not authenticated via the preview URL decorator."));
            }

            if (String.IsNullOrEmpty(linkUrl))
            {
                return(new GetLinkMetadataActionResult(HttpStatusCode.BadRequest, statusCodeMessage: "URL is missing the \"linkUrl\" parameter."));
            }

            LinkModel linkModel = new LinkModel()
            {
                LinkURL  = linkUrl,
                LinkType = LinkTypeEnum.External
            };

            // Try to identify particular local link types
            if (IsLocalUrl(linkUrl))
            {
                LinkModel localLinkModel = null;
                string    urlPath        = GetUrlPath(linkUrl);

                // Media file
                var mediaFile = mediaFilesRetriever.GetMediaFile(urlPath);
                if (mediaFile != null)
                {
                    localLinkModel = GetMediaFileLinkModel(mediaFile);
                }

                // Page
                if (localLinkModel == null)
                {
                    var page = pagesProvider.GetPage(urlPath);
                    if (page != null)
                    {
                        if (!page.CheckPermissions(PermissionsEnum.Read, siteName, MembershipContext.AuthenticatedUser))
                        {
                            return(new GetLinkMetadataActionResult(HttpStatusCode.Forbidden, statusCodeMessage: $"You are not authorized to access data of the page '{urlPath}'."));
                        }

                        localLinkModel = GetPageLinkModel(page);
                    }
                }

                // Local link with of an unknown type
                if (localLinkModel == null)
                {
                    localLinkModel = GetLocalLinkModel();
                }

                // Store the local URL path that does not contain the virtual context data
                localLinkModel.LinkURL = GetAbsolutePath(urlPath);

                linkModel = localLinkModel;
            }

            return(new GetLinkMetadataActionResult(HttpStatusCode.OK, linkModel));
        }
        private LinkModel GetLocalLinkModel()
        {
            var linkModel = new LinkModel
            {
                LinkType = LinkTypeEnum.Local
            };

            return(linkModel);
        }
        private LinkModel GetPageLinkModel(TreeNode page)
        {
            var linkModel = new LinkModel
            {
                LinkType     = LinkTypeEnum.Page,
                LinkMetadata = new LinkMetadata
                {
                    Name       = GetPageName(page),
                    Identifier = page.NodeGUID
                }
            };

            return(linkModel);
        }
        private LinkModel GetMediaFileLinkModel(MediaFileInfo mediaFile)
        {
            var linkModel = new LinkModel
            {
                LinkType     = LinkTypeEnum.MediaFile,
                LinkMetadata = new LinkMetadata
                {
                    Name       = mediaFile.FileName + mediaFile.FileExtension,
                    Identifier = mediaFile.FileGUID
                }
            };

            return(linkModel);
        }
        /// <summary>
        /// Processes the GetLinkMetadata action.
        /// </summary>
        /// <param name="linkUrl">The link URL.</param>
        public GetLinkMetadataActionResult ProcessAction(string linkUrl)
        {
            if (!VirtualContext.IsPreviewLinkInitialized)
            {
                return(new GetLinkMetadataActionResult(HttpStatusCode.Forbidden, statusCodeMessage: "The request is not authenticated via the preview URL decorator."));
            }

            if (String.IsNullOrEmpty(linkUrl))
            {
                return(new GetLinkMetadataActionResult(HttpStatusCode.BadRequest, statusCodeMessage: "URL is missing the \"linkUrl\" parameter."));
            }

            var linkModel = new LinkModel()
            {
                LinkURL = linkUrl
            };

            if (IsLocalUrl(linkUrl))
            {
                string urlPath = GetUrlPath(linkUrl);

                var page = pagesProvider.GetPage(urlPath);
                if (page != null)
                {
                    if (!page.CheckPermissions(PermissionsEnum.Read, SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser))
                    {
                        return(new GetLinkMetadataActionResult(HttpStatusCode.Forbidden, statusCodeMessage: $"You are not authorized to access data of the page '{urlPath}'."));
                    }

                    linkModel = GetPageLinkModel(page);
                }
                else
                {
                    linkModel = GetLocalLinkModel();
                }

                // Store the local URL path that does not contain the virtual context data
                linkModel.LinkURL = GetAbsolutePath(urlPath);
            }

            return(new GetLinkMetadataActionResult(HttpStatusCode.OK, linkModel));
        }
 public GetLinkMetadataActionResult(HttpStatusCode statusCode, LinkModel linkModel = null, string statusCodeMessage = null)
 {
     LinkModel         = linkModel;
     StatusCode        = statusCode;
     StatusCodeMessage = statusCodeMessage;
 }