/// <summary> /// The change image caption. /// </summary> /// <param name="imageID"> /// The Image id. /// </param> /// <param name="newCaption"> /// The New caption. /// </param> /// <returns> /// the return object. /// </returns> public static ReturnClass ChangeImageCaption(int imageID, [NotNull] string newCaption) { // load the DB so YafContext can work... CodeContracts.ArgumentNotNull(newCaption, "newCaption"); YafContext.Current.Get <StartupInitializeDb>().Run(); // newCaption = System.Web.HttpUtility.HtmlEncode(newCaption); LegacyDb.album_image_save(imageID, null, newCaption, null, null, null); var returnObject = new ReturnClass { NewTitle = newCaption }; returnObject.NewTitle = (newCaption == string.Empty) ? YafContext.Current.Get <ILocalization>().GetText("ALBUM", "ALBUM_IMAGE_CHANGE_CAPTION") : newCaption; returnObject.Id = imageID.ToString(); return(returnObject); }
/// <summary> /// Save the attached file both physically and in the db. /// </summary> /// <param name="file">the file.</param> /// <exception cref="Exception">Album Image File is too big</exception> private void SaveAttachment([NotNull] HtmlInputFile file) { if (file.PostedFile == null || file.PostedFile.FileName.Trim().Length == 0 || file.PostedFile.ContentLength == 0) { return; } string sUpDir = this.Get <HttpRequestBase>().MapPath( string.Concat(BaseUrlBuilder.ServerFileRoot, YafBoardFolders.Current.Uploads)); // check if Uploads folder exists if (!Directory.Exists(sUpDir)) { Directory.CreateDirectory(sUpDir); } string filename = file.PostedFile.FileName; int pos = filename.LastIndexOfAny(new[] { '/', '\\' }); if (pos >= 0) { filename = filename.Substring(pos + 1); } // filename can be only 255 characters long (due to table column) if (filename.Length > 255) { filename = filename.Substring(filename.Length - 255); } // verify the size of the attachment if (this.Get <YafBoardSettings>().AlbumImagesSizeMax > 0 && file.PostedFile.ContentLength > this.Get <YafBoardSettings>().AlbumImagesSizeMax) { throw new Exception(this.GetText("ERROR_TOOBIG")); } // vzrus: the checks here are useless but in a case... DataTable sigData = LegacyDb.user_getalbumsdata(this.PageContext.PageUserID, YafContext.Current.PageBoardID); var usrAlbumsAllowed = sigData.GetFirstRowColumnAsValue <int?>("UsrAlbums", null); var usrAlbumImagesAllowed = sigData.GetFirstRowColumnAsValue <int?>("UsrAlbumImages", null); // if (!usrAlbums.HasValue || usrAlbums <= 0) return; if (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a") == "new") { int[] alstats = LegacyDb.album_getstats(this.PageContext.PageUserID, null); // Albums count. If we reached limit then we exit. if (alstats[0] >= usrAlbumsAllowed) { this.PageContext.AddLoadMessage(this.GetTextFormatted("ALBUMS_COUNT_LIMIT", usrAlbumImagesAllowed)); return; } var newAlbumId = LegacyDb.album_save(null, this.PageContext.PageUserID, this.txtTitle.Text, null); file.PostedFile.SaveAs( "{0}/{1}.{2}.{3}.yafalbum".FormatWith(sUpDir, this.PageContext.PageUserID, newAlbumId.ToString(), filename)); LegacyDb.album_image_save(null, newAlbumId, null, filename, file.PostedFile.ContentLength, file.PostedFile.ContentType); // clear the cache for this user to update albums|images stats... this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.PageContext.PageUserID)); YafBuildLink.Redirect(ForumPages.cp_editalbumimages, "a={0}", newAlbumId); } else { // vzrus: the checks here are useless but in a case... int[] alstats = LegacyDb.album_getstats( this.PageContext.PageUserID, this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a")); /* * // Albums count. If we reached limit then we exit. * // Check it first as user could be in other group or prev YAF version was used; * if (DB.album_getstats(this.PageContext.PageUserID, null)[0] >= usrAlbums) * { * this.PageContext.AddLoadMessage(this.GetTextFormatted("ALBUMS_COUNT_LIMIT", usrAlbums)); * return; * }*/ // Images count. If we reached limit then we exit. if (alstats[1] >= usrAlbumImagesAllowed) { this.PageContext.AddLoadMessage(this.GetTextFormatted("IMAGES_COUNT_LIMIT", usrAlbumImagesAllowed)); return; } file.PostedFile.SaveAs( "{0}/{1}.{2}.{3}.yafalbum".FormatWith( sUpDir, this.PageContext.PageUserID, this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a"), filename)); LegacyDb.album_image_save( null, this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a"), null, filename, file.PostedFile.ContentLength, file.PostedFile.ContentType); } }