Exemplo n.º 1
0
        protected void btnDeleteImage_Click(object sender, EventArgs e)
        {
            try
            {
                bool isDeleted = false;
                foreach (GridDataItem data in grid.SelectedItems)
                {
                    Guid guid = new Guid(data.GetDataKeyValue("Guid").ToString());

                    ContentMedia media = new ContentMedia(guid);
                    if (media != null && media.Guid != Guid.Empty)
                    {
                        NewsHelper.DeleteImages(media, fileSystem, imageFolderPath);
                        ContentMedia.Delete(guid);

                        isDeleted = true;
                    }
                }

                if (isDeleted)
                {
                    grid.Rebind();
                    updImages.Update();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
Exemplo n.º 2
0
        protected string getFileNameImage(int newsId)
        {
            var    news     = new News(siteSettings.SiteId, newsId);
            string fileName = ContentMedia.GetByContentAsc(news.NewsGuid).Select(x => x.MediaFile).FirstOrDefault();

            return(fileName);
        }
Exemplo n.º 3
0
        public bool DeleteContent(string newsId)
        {
            try
            {
                SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
                News         news         = new News(siteSettings.SiteId, Convert.ToInt32(newsId));

                if (news != null && news.NewsID != -1)
                {
                    NewsHelper.DeleteFolder(siteSettings.SiteId, news.NewsID);

                    ContentMedia.DeleteByContent(news.NewsGuid);

                    var listAtributes = ContentAttribute.GetByContentAsc(news.NewsGuid);
                    foreach (ContentAttribute item in listAtributes)
                    {
                        ContentLanguage.DeleteByContent(item.Guid);
                    }
                    ContentAttribute.DeleteByContent(news.NewsGuid);
                    ContentLanguage.DeleteByContent(news.NewsGuid);

                    news.Delete();
                    FriendlyUrl.DeleteByPageGuid(news.NewsGuid);

                    FileAttachment.DeleteByItem(news.NewsGuid);
                }
            }
            catch (Exception) { return(false); }

            return(true);
        }
Exemplo n.º 4
0
        public void BuildProductImagesXml(
            XmlDocument doc,
            XmlElement root,
            ContentMedia media,
            string imageFolderPath,
            string thumbnailImageFolderPath)
        {
            string elementName = "ProductImages";

            if (media.MediaType == (int)ProductMediaType.Image1)
            {
                elementName = "ProductImages1";
            }
            else if (media.MediaType == (int)ProductMediaType.Image2)
            {
                elementName = "ProductImages2";
            }
            XmlElement element = doc.CreateElement(elementName);

            root.AppendChild(element);

            XmlHelper.AddNode(doc, element, "Title", media.Title);
            XmlHelper.AddNode(doc, element, "Type", media.MediaType.ToString());
            XmlHelper.AddNode(doc, element, "ImageUrl", ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile));
            XmlHelper.AddNode(doc, element, "ThumbnailUrl", ProductHelper.GetMediaFilePath(thumbnailImageFolderPath,
                                                                                           media.ThumbnailFile));
        }
Exemplo n.º 5
0
        public static void DeleteImages(ContentMedia contentImage, IFileSystem fileSystem, string virtualRoot)
        {
            string imageVirtualPath = virtualRoot + contentImage.MediaFile;

            fileSystem.DeleteFile(imageVirtualPath);

            imageVirtualPath = virtualRoot + "thumbs/" + contentImage.ThumbnailFile;
            fileSystem.DeleteFile(imageVirtualPath);
        }
Exemplo n.º 6
0
        public async Task AddImageAsync(Content content, ContentMedia media)
        {
            if (content.Media == null)
            {
                content.Media = new List <ContentMedia>();
            }

            content.Media.Add(media);
            await UpdateAsync(content);
        }
Exemplo n.º 7
0
        protected void btnUpdateImage_Click(object sender, EventArgs e)
        {
            if (news == null)
            {
                return;
            }

            //txtImageTitle.Text = txtImageTitle.Text.Trim();
            NewsHelper.VerifyNewsFolders(fileSystem, imageFolderPath);

            foreach (UploadedFile file in uplImageFile.UploadedFiles)
            {
                string ext = file.GetExtension();
                if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                {
                    ContentMedia image = new ContentMedia();
                    image.SiteGuid    = siteSettings.SiteGuid;
                    image.ContentGuid = news.NewsGuid;
                    //image.Title = txtImageTitle.Text;
                    image.DisplayOrder = 0;

                    string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                    string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                    if (image.MediaFile == newFileName)
                    {
                        // an existing image delete the old one
                        fileSystem.DeleteFile(newImagePath);
                    }
                    else
                    {
                        // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                        int i = 1;
                        while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                        {
                            newFileName = i.ToInvariantString() + newFileName;
                            i          += 1;
                        }
                    }

                    newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                    file.SaveAs(Server.MapPath(newImagePath));

                    image.MediaFile       = newFileName;
                    image.ThumbnailFile   = newFileName;
                    image.ThumbNailWidth  = displaySettings.ThumbnailWidth;
                    image.ThumbNailHeight = displaySettings.ThumbnailHeight;
                    image.Save();
                    NewsHelper.ProcessImage(image, fileSystem, imageFolderPath, file.FileName, NewsHelper.GetColor(displaySettings.ResizeBackgroundColor));
                }
            }
            grid.Rebind();
            updImages.Update();
        }
Exemplo n.º 8
0
        public async Task <Content> DuplicateContentAsync(int id)
        {
            Content clone = await _db.Content
                            .AsNoTracking()
                            .SingleOrDefaultAsync(c => c.Id == id);

            if (clone == null)
            {
                return(null);
            }

            clone.Id          = 0;
            clone.Title      += " - Copy";
            clone.Slug       += "-copy";
            clone.PublishDate = DateTime.UtcNow;
            clone.CreatedOn   = DateTime.UtcNow;

            _db.Content.Add(clone);
            await _db.SaveChangesAsync();

            Content copyObject = await _db.Content
                                 .AsNoTracking()
                                 .Include(p => p.Categories).ThenInclude(c => c.Category)
                                 .Include(p => p.Media)
                                 .Include(p => p.Metadata)
                                 .SingleOrDefaultAsync(c => c.Id == id);

            clone.Categories = new List <ContentCategoryJoin>();
            foreach (ContentCategoryJoin c in copyObject.Categories)
            {
                clone.Categories.Add(new ContentCategoryJoin()
                {
                    ContentId = clone.Id, CategoryId = c.CategoryId
                });
            }
            clone.Media = new List <ContentMedia>();
            foreach (ContentMedia c in copyObject.Media)
            {
                ContentMedia newMedia = new ContentMedia();
                c.CopyProperties(newMedia);
                newMedia.Id = 0;
                clone.Media.Add(newMedia);
            }
            clone.Metadata = new List <ContentMeta>();
            foreach (ContentMeta c in copyObject.Metadata)
            {
                ContentMeta newMeta = new ContentMeta();
                c.CopyProperties(newMeta);
                newMeta.Id = 0;
                clone.Metadata.Add(newMeta);
            }
            await _db.SaveChangesAsync();

            return(clone);
        }
Exemplo n.º 9
0
        protected List <string> GetListImageSlider(int newsId)
        {
            List <string> lstImageSlider = new List <string>();
            var           news           = new News(siteSettings.SiteId, newsId);
            List <string> filenames      = ContentMedia.GetByContentAsc(news.NewsGuid).Select(x => x.MediaFile).ToList();

            foreach (var filename in filenames)
            {
                string urlImage = "/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/News/" + newsId + "/" + filename;
                lstImageSlider.Add(urlImage);
            }
            return(lstImageSlider);
        }
Exemplo n.º 10
0
        public void BuildNewsImagesXml(
            XmlDocument doc,
            XmlElement root)
        {
            string imageFolderPath          = NewsHelper.MediaFolderPath(basePage.SiteId, news.NewsID);
            string thumbnailImageFolderPath = imageFolderPath + "thumbs/";
            string siteRoot = WebUtils.GetSiteRoot();

            int    defaultLanguageId = -1;
            string defaultCulture    = WebConfigSettings.DefaultLanguageCulture;

            if (defaultCulture.Length > 0)
            {
                defaultLanguageId = LanguageHelper.GetLanguageIdByCulture(defaultCulture);
            }

            List <int>          listDisplayOrder = new List <int>();
            List <ContentMedia> listMedia        = ContentMedia.GetByContentDesc(news.NewsGuid);

            foreach (ContentMedia media in listMedia)
            {
                if (media.LanguageId == -1 || media.LanguageId == languageId || (languageId == -1 && media.LanguageId == defaultLanguageId))
                {
                    BuildNewsImagesXml(doc, root, media, imageFolderPath, thumbnailImageFolderPath);

                    if (displaySettings.ShowGroupImages)
                    {
                        if (!listDisplayOrder.Contains(media.DisplayOrder))
                        {
                            listDisplayOrder.Add(media.DisplayOrder);
                            XmlElement groupImages = doc.CreateElement("GroupImages");
                            root.AppendChild(groupImages);
                            XmlHelper.AddNode(doc, groupImages, "DisplayOrder", media.DisplayOrder.ToString());

                            foreach (ContentMedia media2 in listMedia)
                            {
                                if ((media2.LanguageId == -1 || media2.LanguageId == languageId || (languageId == -1 && media2.LanguageId == defaultLanguageId)) &&
                                    (media2.DisplayOrder == media.DisplayOrder))
                                {
                                    BuildNewsImagesXml(doc, groupImages, media2, imageFolderPath, thumbnailImageFolderPath);
                                }
                            }
                        }
                    }

                    string relativePath = siteRoot + Page.ResolveUrl(imageFolderPath + media.MediaFile);
                    basePage.AdditionalMetaMarkup += "\n<meta property=\"og:image\" content=\"" + relativePath + "\" />";
                    basePage.AdditionalMetaMarkup += "\n<meta itemprop=\"image\" content=\"" + relativePath + "\" />";
                }
            }
        }
Exemplo n.º 11
0
        public static void ProcessImage(ContentMedia contentImage, IFileSystem fileSystem, string virtualRoot, string originalFileName, Color backgroundColor)
        {
            string originalPath  = virtualRoot + contentImage.MediaFile;
            string thumbnailPath = virtualRoot + "thumbs/" + contentImage.ThumbnailFile;

            fileSystem.CopyFile(originalPath, thumbnailPath, true);

            CanhCam.Web.ImageHelper.ResizeImage(
                thumbnailPath,
                IOHelper.GetMimeType(Path.GetExtension(thumbnailPath)),
                contentImage.ThumbNailWidth,
                contentImage.ThumbNailHeight,
                backgroundColor);
        }
Exemplo n.º 12
0
        public static void DeleteImages(ContentMedia contentImage, IFileSystem fileSystem, string virtualRoot)
        {
            string imageVirtualPath = virtualRoot + contentImage.MediaFile;

            if (!contentImage.MediaFile.ContainsCaseInsensitive("/"))
            {
                fileSystem.DeleteFile(imageVirtualPath);
            }

            if (!contentImage.ThumbnailFile.ContainsCaseInsensitive("/"))
            {
                imageVirtualPath = virtualRoot + "thumbs/" + contentImage.ThumbnailFile;
                fileSystem.DeleteFile(imageVirtualPath);
            }
        }
Exemplo n.º 13
0
        protected void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            List <ContentMedia> listMedia = null;

            if (news != null)
            {
                listMedia       = ContentMedia.GetByContentDesc(news.NewsGuid);
                grid.DataSource = listMedia;

                if (listMedia.Count > 0)
                {
                    btnDeleteImage.Visible = true;
                }
            }
        }
Exemplo n.º 14
0
        public void BuildNewsImagesXml(
            XmlDocument doc,
            XmlElement root,
            ContentMedia media,
            string imageFolderPath,
            string thumbnailImageFolderPath)
        {
            XmlElement element = doc.CreateElement("NewsImages");

            root.AppendChild(element);

            XmlHelper.AddNode(doc, element, "Title", media.Title);
            XmlHelper.AddNode(doc, element, "DisplayOrder", media.DisplayOrder.ToString());
            XmlHelper.AddNode(doc, element, "ImageUrl", Page.ResolveUrl(imageFolderPath + media.MediaFile));
            XmlHelper.AddNode(doc, element, "ThumbnailUrl", Page.ResolveUrl(thumbnailImageFolderPath + media.ThumbnailFile));
        }
Exemplo n.º 15
0
        public virtual async Task <Response> RemoveMedia(int id, int mediaId)
        {
            try
            {
                ContentMedia media = await _db.ContentMedia.SingleOrDefaultAsync(m => m.Id == mediaId);

                _db.Entry(media).State = EntityState.Deleted;
                await _db.SaveChangesAsync();

                return(new Response(true, "The image has now been removed."));
            }
            catch (Exception ex)
            {
                await _logService.AddExceptionAsync <BaseContentController>("Error removing media item.", ex);

                return(new Response(ex));
            }
        }
Exemplo n.º 16
0
        public virtual async Task <Response> UploadToGallery(List <int> media, int id)
        {
            try
            {
                Content content = await _content.GetContentByIdAsync(id);

                if (content == null)
                {
                    throw new Exception("Content not found!");
                }

                if (media != null)
                {
                    if (media.Count == 0)
                    {
                        throw new Exception("There are no files selected!");
                    }

                    var directory = await _property.GetDirectoryAsync();

                    foreach (int mediaId in media)
                    {
                        // load the media object from db
                        MediaObject mediaObject = _db.Media.AsNoTracking().SingleOrDefault(m => m.Id == mediaId);
                        if (media == null)
                        {
                            throw new Exception("Could not load media to attach.");
                        }
                        var propertyMedia = new ContentMedia(mediaObject);
                        propertyMedia.ContentId = content.Id;
                        propertyMedia.Id        = 0;
                        _db.ContentMedia.Add(propertyMedia);
                        await _db.SaveChangesAsync();
                    }
                }
                return(new Response(true, "The media has been attached successfully."));
            }
            catch (Exception ex)
            {
                return(await ErrorResponseAsync <BaseContentController>($"Error uploading media to the gallery.", ex));
            }
        }
Exemplo n.º 17
0
        public bool DeleteContent(string productId)
        {
            try
            {
                SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
                Product      product      = new Product(siteSettings.SiteId, Convert.ToInt32(productId));

                if (product != null && product.ProductId != -1)
                {
                    ProductHelper.DeleteFolder(siteSettings.SiteId, product.ProductId);

                    ContentMedia.DeleteByContent(product.ProductGuid);
                    ShoppingCartItem.DeleteByProduct(product.ProductId);

                    var listAtributes = ContentAttribute.GetByContentAsc(product.ProductGuid);
                    foreach (ContentAttribute item in listAtributes)
                    {
                        ContentLanguage.DeleteByContent(item.Guid);
                    }
                    ContentAttribute.DeleteByContent(product.ProductGuid);
                    ContentLanguage.DeleteByContent(product.ProductGuid);

                    ProductProperty.DeleteByProduct(product.ProductId);
                    FriendlyUrl.DeleteByPageGuid(product.ProductGuid);

                    ProductComment.DeleteByProduct(product.ProductId);
                    TagItem.DeleteByItem(product.ProductGuid);

                    FileAttachment.DeleteByItem(product.ProductGuid);
                    RelatedItem.DeleteByItem(product.ProductGuid);

                    product.Delete();
                }
            }
            catch (Exception) { return(false); }

            return(true);
        }
Exemplo n.º 18
0
        public void BuildNewsImagesXml(
            XmlDocument doc,
            XmlElement newsXml,
            News news,
            int languageId)
        {
            string imageFolderPath          = NewsHelper.MediaFolderPath(SiteId, news.NewsID);
            string thumbnailImageFolderPath = imageFolderPath + "thumbs/";

            List <ContentMedia> listMedia = ContentMedia.GetByContentDesc(news.NewsGuid);

            foreach (ContentMedia media in listMedia)
            {
                if (media.LanguageId == -1 || media.LanguageId == languageId)
                {
                    XmlElement element = doc.CreateElement("NewsImages");
                    newsXml.AppendChild(element);

                    XmlHelper.AddNode(doc, element, "Title", media.Title);
                    XmlHelper.AddNode(doc, element, "ImageUrl", Page.ResolveUrl(imageFolderPath + media.MediaFile));
                    XmlHelper.AddNode(doc, element, "ThumbnailUrl", Page.ResolveUrl(thumbnailImageFolderPath + media.ThumbnailFile));
                }
            }
        }
Exemplo n.º 19
0
        private int Save()
        {
            checkpass();
            if (comfim)
            {
                try
                {
                    var    full = txtFullName.Text.Trim().Split(' ');
                    string Fist = "";
                    string Last = "";
                    for (int i = 0; i < full.Length; i++)
                    {
                        if ((i + 1) < full.Length)
                        {
                            Last += full[i];
                        }
                        else
                        {
                            Fist += full[i];
                        }
                    }
                    SiteUser user = new SiteUser(siteSettings)
                    {
                        Name      = txtFullName.Text.Trim(),
                        FirstName = Fist,
                        LastName  = Last,
                        Email     = txtEmail.Text.Trim(),
                        LoginName = txtFullName.Text.Trim().Replace(' ', '-'),
                        Password  = txtPass2.Text,
                    };
                    user.Save();
                    user = new SiteUser(siteSettings, txtFullName.Text.Replace(' ', '-'));
                    KLAuthor author = null;

                    imageFolderPath = AuthorHepper.MediaFolderPath(siteSettings.SiteId, user.UserId);
                    if (user.Save())
                    {
                        author = new KLAuthor()
                        {
                            ArticleCount = 0,
                            UserID       = user.UserId,
                            IsDel        = false,
                            LevelAuthor  = "Basic",
                            Name         = txtFullName.Text,
                            IsActive     = false,
                        };
                        if (fileImage.UploadedFiles.Count > 0)
                        {
                            imageFolderPath = AuthorHepper.MediaFolderPath(siteSettings.SiteId, user.UserId);


                            AuthorHepper.VerifyAuthorFolders(fileSystem, imageFolderPath);

                            foreach (UploadedFile file in fileImage.UploadedFiles)
                            {
                                string ext = file.GetExtension();
                                if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                                {
                                    ContentMedia media = new ContentMedia();
                                    media.SiteGuid = siteSettings.SiteGuid;
                                    //image.Title = txtImageTitle.Text;
                                    media.DisplayOrder = 0;

                                    string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                                    string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                                    if (media.MediaFile == newFileName)
                                    {
                                        // an existing image delete the old one
                                        fileSystem.DeleteFile(newImagePath);
                                    }
                                    else
                                    {
                                        // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                                        int i = 1;
                                        while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                                        {
                                            newFileName = i.ToInvariantString() + newFileName;
                                            i          += 1;
                                        }
                                    }

                                    newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                                    file.SaveAs(Server.MapPath(newImagePath));

                                    media.MediaFile     = newFileName;
                                    media.ThumbnailFile = newFileName;

                                    author.Avatar = newFileName;
                                    media.Save();
                                    AuthorHepper.ProcessImage(media, fileSystem, imageFolderPath, file.FileName);
                                }
                            }
                        }
                    }
                    author.Save();

                    Role role = new Role(siteSettings.SiteId, "Author");
                    Role.AddUser(role.RoleId, author.UserID, role.RoleGuid, user.UserGuid);

                    if (!sendmail(user.Name, user.Email))
                    {
                        return(-1);
                    }

                    return(author.UserID);
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                }
            }
            return(-1);
        }
Exemplo n.º 20
0
        private void BuildProductMediaXml(
            XmlDocument doc,
            XmlElement root)
        {
            string imageFolderPath          = ProductHelper.MediaFolderPath(CacheHelper.GetCurrentSiteSettings().SiteId, product.ProductId);
            string thumbnailImageFolderPath = imageFolderPath + "thumbs/";
            string siteRoot = WebUtils.GetSiteRoot();

            Regex youtubeVideoRegex       = new Regex("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)");
            List <ContentMedia> listMedia = ContentMedia.GetByContentDesc(product.ProductGuid);

            List <int> mediaTypes = new List <int>();
            List <CustomFieldOption> listOptions = new List <CustomFieldOption>();

            foreach (ContentMedia media in listMedia)
            {
                if (media.MediaType > 0 && !mediaTypes.Contains(media.MediaType))
                {
                    mediaTypes.Add(media.MediaType);
                }
            }
            if (mediaTypes.Count > 0)
            {
                listOptions = CustomFieldOption.GetByOptionIds(product.SiteId, string.Join(";", mediaTypes.ToArray()));
            }

            if (listOptions.Count > 0)
            {
                foreach (CustomFieldOption option in listOptions)
                {
                    XmlElement element = doc.CreateElement("ProductColors");
                    root.AppendChild(element);
                    XmlHelper.AddNode(doc, element, "Title", option.Name);
                    XmlHelper.AddNode(doc, element, "Color", option.OptionColor);
                    XmlHelper.AddNode(doc, element, "ColorId", option.CustomFieldOptionId.ToString());

                    foreach (ContentMedia media in listMedia)
                    {
                        if (
                            (option.CustomFieldOptionId == media.MediaType) &&
                            (media.LanguageId == -1 || media.LanguageId == languageId) &&
                            (media.MediaType != (int)ProductMediaType.Video)
                            )
                        {
                            BuildProductImagesXml(doc, element, media, imageFolderPath, thumbnailImageFolderPath);
                        }
                    }
                }
            }

            foreach (ContentMedia media in listMedia)
            {
                if (media.LanguageId == -1 || media.LanguageId == languageId)
                {
                    if (media.MediaType != (int)ProductMediaType.Video)
                    {
                        BuildProductImagesXml(doc, root, media, imageFolderPath, thumbnailImageFolderPath);

                        if (media.MediaType != (int)ProductMediaType.Image)
                        {
                            string relativePath = siteRoot + ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile);
                            basePage.AdditionalMetaMarkup += "\n<meta property=\"og:image\" content=\"" + relativePath + "\" />";
                            basePage.AdditionalMetaMarkup += "\n<meta itemprop=\"image\" content=\"" + relativePath + "\" />";
                        }
                    }
                    else
                    {
                        XmlElement element = doc.CreateElement("ProductVideos");
                        root.AppendChild(element);

                        XmlHelper.AddNode(doc, element, "Title", media.Title);
                        XmlHelper.AddNode(doc, element, "DisplayOrder", media.DisplayOrder.ToString());
                        XmlHelper.AddNode(doc, element, "Type", media.MediaType.ToString());
                        XmlHelper.AddNode(doc, element, "VideoUrl", ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile));

                        string thumbnailPath = ProductHelper.GetMediaFilePath(thumbnailImageFolderPath, media.ThumbnailFile);
                        if (media.ThumbnailFile.Length == 0 && media.MediaFile.ContainsCaseInsensitive("youtu"))
                        {
                            Match  youtubeMatch = youtubeVideoRegex.Match(media.MediaFile);
                            string videoId      = string.Empty;
                            if (youtubeMatch.Success)
                            {
                                videoId = youtubeMatch.Groups[1].Value;
                            }

                            thumbnailPath = "http://img.youtube.com/vi/" + videoId + "/0.jpg";
                        }

                        XmlHelper.AddNode(doc, element, "ThumbnailUrl", thumbnailPath);
                    }

                    if (displaySettings.ShowVideo)
                    {
                        XmlElement element = doc.CreateElement("ProductMedia");
                        root.AppendChild(element);

                        XmlHelper.AddNode(doc, element, "Title", media.Title);
                        XmlHelper.AddNode(doc, element, "DisplayOrder", media.DisplayOrder.ToString());
                        XmlHelper.AddNode(doc, element, "Type", media.MediaType.ToString());
                        XmlHelper.AddNode(doc, element, "MediaUrl", ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile));
                        XmlHelper.AddNode(doc, element, "ThumbnailUrl", ProductHelper.GetMediaFilePath(thumbnailImageFolderPath, media.ThumbnailFile));
                    }
                }
            }
        }
Exemplo n.º 21
0
        private int Save()
        {
            Page.Validate("Books");

            if (!Page.IsValid)
            {
                return(-1);
            }

            if (currentuser == null)
            {
                return(-1);
            }
            if (book == null)
            {
                book            = new KLBook();
                book.AuthorID   = author.AuthorID;
                book.IsPublish  = true;
                book.IsDelected = false;
            }
            book.Title       = txttitle.Text;
            book.Url         = txtURl.Text;
            book.Description = fullcontent.Text;
            if (book.Save())
            {
                imageFolderPath = BookHelper.MediaFolderPath(siteSettings.SiteId, book.BookID);

                if (fileImages.UploadedFiles.Count > 0)
                {
                    BookHelper.VerifyBookFolders(fileSystem, imageFolderPath);

                    foreach (UploadedFile file in fileImages.UploadedFiles)
                    {
                        string ext = file.GetExtension();
                        if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                        {
                            ContentMedia media = new ContentMedia();
                            media.SiteGuid = siteSettings.SiteGuid;
                            //image.Title = txtImageTitle.Text;
                            media.DisplayOrder = 0;

                            string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                            string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                            if (media.MediaFile == newFileName)
                            {
                                // an existing image delete the old one
                                fileSystem.DeleteFile(newImagePath);
                            }
                            else
                            {
                                // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                                int i = 1;
                                while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                                {
                                    newFileName = i.ToInvariantString() + newFileName;
                                    i          += 1;
                                }
                            }

                            newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                            file.SaveAs(Server.MapPath(newImagePath));

                            media.MediaFile     = newFileName;
                            media.ThumbnailFile = newFileName;

                            book.Image = newFileName;
                            media.Save();
                            BookHelper.ProcessImage(media, fileSystem, imageFolderPath, file.FileName);
                        }
                    }
                }
            }
            if (book.Save())
            {
                LogActivity.Write("Create new news", book.Title);
                message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "InsertSuccessMessage");
            }
            return(book.BookID);
        }
Exemplo n.º 22
0
        private int Save()
        {
            Page.Validate("Author");

            if (!Page.IsValid)
            {
                return(-1);
            }
            try
            {
                author.LinkFacebook  = txtfb.Text;
                author.LinkInstagram = txtinstagram.Text;
                author.LinkPinterest = txtpinterest.Text;
                author.LinkTwitter   = txttwinter.Text;
                author.Name          = txtFullName.Text;
                SiteUser temp = new SiteUser(siteSettings, author.UserID);
                temp.Signature = editDescription.Text;
                if (fileImage.UploadedFiles.Count > 0)
                {
                    imageFolderPath = AuthorHepper.MediaFolderPath(siteSettings.SiteId, author.UserID);


                    AuthorHepper.VerifyAuthorFolders(fileSystem, imageFolderPath);

                    foreach (UploadedFile file in fileImage.UploadedFiles)
                    {
                        string ext = file.GetExtension();
                        if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                        {
                            ContentMedia media = new ContentMedia();
                            media.SiteGuid = siteSettings.SiteGuid;
                            //image.Title = txtImageTitle.Text;
                            media.DisplayOrder = 0;

                            string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                            string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                            if (media.MediaFile == newFileName)
                            {
                                // an existing image delete the old one
                                fileSystem.DeleteFile(newImagePath);
                            }
                            else
                            {
                                // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                                int i = 1;
                                while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                                {
                                    newFileName = i.ToInvariantString() + newFileName;
                                    i          += 1;
                                }
                            }

                            newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                            file.SaveAs(Server.MapPath(newImagePath));

                            media.MediaFile     = newFileName;
                            media.ThumbnailFile = newFileName;

                            author.Avatar = newFileName;
                            media.Save();
                            AuthorHepper.ProcessImage(media, fileSystem, imageFolderPath, file.FileName);
                        }
                    }
                }


                if (temp.Save() && author.Save())
                {
                    ImageAvatar.ImageUrl = AuthorHepper.GetAvatarAuthor(siteSettings.SiteId, author.UserID);
                    LogActivity.Write("Update Author", author.Name);
                    message.SuccessMessage = ResourceHelper.GetResourceString("CustomResources", "UpdateAuthorSuccess");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            return(author.AuthorID);
        }