Example #1
0
        public ActionResult Index(string folderPath, string type, int?replaceId)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission
            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new OEmbedViewModel {
                FolderPath = folderPath,
            };

            if (replaceId != null)
            {
                var replaceMedia = Services.ContentManager.Get <MediaPart>(replaceId.Value);
                if (replaceMedia == null)
                {
                    return(HttpNotFound());
                }

                viewModel.Replace = replaceMedia;

                if (!replaceMedia.TypeDefinition.Name.Equals("OEmbed"))
                {
                    Services.Notifier.Error(T("Cannot replace {0} with OEmbed", replaceMedia.ContentItem.TypeDefinition.Name));
                }
            }

            return(View(viewModel));
        }
Example #2
0
        public ActionResult MediaPost(string folderPath, string url, string document)
        {
            var content = XDocument.Parse(document);
            var oembed  = content.Root;

            var part = Services.ContentManager.New <MediaPart>("OEmbed");


            part.MimeType   = "text/html";
            part.FolderPath = folderPath;
            part.Title      = oembed.Element("title").Value;
            if (oembed.Element("description") != null)
            {
                part.Caption = oembed.Element("description").Value;
            }
            var oembedPart = part.As <OEmbedPart>();

            oembedPart.Source = url;

            foreach (var element in oembed.Elements())
            {
                oembedPart[element.Name.LocalName] = element.Value;
            }


            Services.ContentManager.Create(oembedPart);

            var viewModel = new OEmbedViewModel {
                FolderPath = folderPath
            };

            return(View("Index", viewModel));
        }
Example #3
0
        public ActionResult Index(string folderPath)
        {
            var viewModel = new OEmbedViewModel {
                FolderPath = folderPath
            };

            return(View(viewModel));
        }
Example #4
0
        public ActionResult IndexPOST(string folderPath, string url, string type)
        {
            var viewModel = new OEmbedViewModel {
                Url        = url,
                FolderPath = folderPath,
                Type       = type
            };

            var webClient = new WebClient {
                Encoding = Encoding.UTF8
            };

            try {
                // <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed">

                var source = webClient.DownloadString(url);

                // seek type="text/xml+oembed" or application/xml+oembed
                var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                if (oembedSignature == -1)
                {
                    oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                }
                if (oembedSignature != -1)
                {
                    var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<');
                    var tagEnd   = source.IndexOf('>', oembedSignature);
                    var tag      = source.Substring(tagStart, tagEnd - tagStart);
                    var matches  = new Regex("href=\"([^\"]+)\"").Matches(tag);
                    if (matches.Count > 0)
                    {
                        var href = matches[0].Groups[1].Value;
                        try {
                            var content = webClient.DownloadString(Server.HtmlDecode(href));
                            viewModel.Content = XDocument.Parse(content);
                        }
                        catch {
                            // bubble exception
                        }
                    }
                }
            }
            catch {
                return(View(viewModel));
            }

            return(View(viewModel));
        }
    public async Task <IActionResult> UpdateDescriptionAsync([FromForm] UpdateDescription updateDescription)
    {
        var video = await _getVideoService.ExecuteAsync(updateDescription.VideoId);

        if (video?.Data == null)
        {
            return(NotFound($"Video Not Found {updateDescription.VideoId}"));
        }

        var oEmbed = await _getOEmbedVideoService.ExecuteAsync(video.Data.Link);

        if (oEmbed?.Data == null)
        {
            return(NotFound($"Video Not Found {updateDescription.VideoId}"));
        }

        var spec         = new ArchiveVideoByVideoIdSpec(updateDescription.VideoId !);
        var archiveVideo = await _repository.GetBySpecAsync(spec);

        if (archiveVideo == null)
        {
            return(NotFound($"Video Not Found {updateDescription.VideoId}"));
        }

        archiveVideo.Description = updateDescription.Description;
        await _repository.UpdateAsync(archiveVideo);

        await _repository.SaveChangesAsync();

        var oEmbedViewModel = new OEmbedViewModel(oEmbed.Data);

        oEmbedViewModel.VideoId       = int.Parse(archiveVideo.VideoId !);
        oEmbedViewModel.DescriptionMd = _markdownService.RenderHTMLFromMD(archiveVideo.Description);
        oEmbedViewModel.Description   = archiveVideo.Description;
        oEmbedViewModel
        .BuildHtml(video.Data.Link);

        return(Ok(oEmbedViewModel));
    }
Example #6
0
        public ActionResult IndexPOST(string folderPath, string url, string type, string title, string html, string thumbnail, string width, string height, string description, int?replaceId)
        {
            var viewModel = new OEmbedViewModel {
                Url        = url,
                FolderPath = folderPath,
            };

            if (replaceId != null)
            {
                var replaceMedia = Services.ContentManager.Get <MediaPart>(replaceId.Value);
                if (replaceMedia == null)
                {
                    return(HttpNotFound());
                }

                viewModel.Replace = replaceMedia;

                if (!replaceMedia.ContentItem.TypeDefinition.Name.Equals("OEmbed"))
                {
                    Services.Notifier.Error(T("Cannot replace {0} with OEmbed", replaceMedia.ContentItem.TypeDefinition.Name));
                    return(View(viewModel));
                }
            }

            var webClient = new WebClient {
                Encoding = Encoding.UTF8
            };

            try {
                // <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed">

                var source = webClient.DownloadString(url);

                // seek type="text/xml+oembed" or application/xml+oembed
                var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                if (oembedSignature == -1)
                {
                    oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                }
                if (oembedSignature != -1)
                {
                    var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<');
                    var tagEnd   = source.IndexOf('>', oembedSignature);
                    var tag      = source.Substring(tagStart, tagEnd - tagStart);
                    var matches  = new Regex("href=\"([^\"]+)\"").Matches(tag);
                    if (matches.Count > 0)
                    {
                        var href = matches[0].Groups[1].Value;
                        try {
                            var content = webClient.DownloadString(Server.HtmlDecode(href));
                            viewModel.Content = XDocument.Parse(content);
                        }
                        catch {
                            // bubble exception
                        }
                    }
                }
                if (viewModel.Content == null)
                {
                    viewModel.Content = new XDocument(
                        new XDeclaration("1.0", "utf-8", "yes"),
                        new XElement("oembed")
                        );
                }
                var root = viewModel.Content.Root;
                if (!String.IsNullOrWhiteSpace(url))
                {
                    root.El("url", url);
                }
                if (!String.IsNullOrWhiteSpace(type))
                {
                    root.El("type", type.ToLowerInvariant());
                }
                if (!String.IsNullOrWhiteSpace(title))
                {
                    root.El("title", title);
                }
                if (!String.IsNullOrWhiteSpace(html))
                {
                    root.El("html", html);
                }
                if (!String.IsNullOrWhiteSpace(thumbnail))
                {
                    root.El("thumbnail", thumbnail);
                }
                if (!String.IsNullOrWhiteSpace(width))
                {
                    root.El("width", width);
                }
                if (!String.IsNullOrWhiteSpace(height))
                {
                    root.El("height", height);
                }
                if (!String.IsNullOrWhiteSpace(description))
                {
                    root.El("description", description);
                }
                Response.AddHeader("X-XSS-Protection", "0"); // Prevents Chrome from freaking out over embedded preview
            }
            catch {
                return(View(viewModel));
            }

            return(View(viewModel));
        }
Example #7
0
        public ActionResult IndexPOST(string folderPath, string url, string type, string title, string html, string thumbnail, string width, string height, string description)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia))
            {
                return(new HttpUnauthorizedResult());
            }

            // Check permission.
            var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder();

            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new OEmbedViewModel {
                Url        = url,
                FolderPath = folderPath
            };

            var webClient = new WebClient {
                Encoding = Encoding.UTF8
            };

            try {
                // <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed">

                var source = webClient.DownloadString(url);

                // seek type="text/xml+oembed" or application/xml+oembed
                var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                if (oembedSignature == -1)
                {
                    oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                }
                if (oembedSignature != -1)
                {
                    var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<');
                    var tagEnd   = source.IndexOf('>', oembedSignature);
                    var tag      = source.Substring(tagStart, tagEnd - tagStart);
                    var matches  = new Regex("href=\"([^\"]+)\"").Matches(tag);
                    if (matches.Count > 0)
                    {
                        var href = matches[0].Groups[1].Value;
                        try {
                            var content = webClient.DownloadString(Server.HtmlDecode(href));
                            viewModel.Content = XDocument.Parse(content);
                        }
                        catch {
                            // bubble exception
                        }
                    }
                }
                if (viewModel.Content == null)
                {
                    viewModel.Content = new XDocument(
                        new XDeclaration("1.0", "utf-8", "yes"),
                        new XElement("oembed")
                        );
                }
                var root = viewModel.Content.Root;
                if (!String.IsNullOrWhiteSpace(url))
                {
                    root.El("url", url);
                }
                if (!String.IsNullOrWhiteSpace(type))
                {
                    root.El("type", type.ToLowerInvariant());
                }
                if (!String.IsNullOrWhiteSpace(title))
                {
                    root.El("title", title);
                }
                if (!String.IsNullOrWhiteSpace(html))
                {
                    root.El("html", html);
                }
                if (!String.IsNullOrWhiteSpace(thumbnail))
                {
                    root.El("thumbnail", thumbnail);
                }
                if (!String.IsNullOrWhiteSpace(width))
                {
                    root.El("width", width);
                }
                if (!String.IsNullOrWhiteSpace(height))
                {
                    root.El("height", height);
                }
                if (!String.IsNullOrWhiteSpace(description))
                {
                    root.El("description", description);
                }
                Response.AddHeader("X-XSS-Protection", "0"); // Prevents Chrome from freaking out over embedded preview
            }
            catch {
                return(View(viewModel));
            }

            return(View(viewModel));
        }