예제 #1
0
        /// <summary>
        /// The ItemCommand method for the cover buttons. Sets/Removes cover image.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param>
        protected void AlbumImages_ItemCommand([NotNull] object sender, [NotNull] CommandEventArgs e)
        {
            using (var dt = LegacyDb.album_list(null, this.AlbumID))
            {
                if (dt.Rows[0]["CoverImageID"].ToString() == e.CommandArgument.ToString())
                {
                    LegacyDb.album_save(this.AlbumID, null, null, 0);
                }
                else
                {
                    LegacyDb.album_save(dt.Rows[0]["AlbumID"], null, null, e.CommandArgument);
                }
            }

            this.BindData();
        }
예제 #2
0
        /// <summary>
        /// Update the album title.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void UpdateTitle_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            string albumID = this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a");

            this.txtTitle.Text = HttpUtility.HtmlEncode(this.txtTitle.Text);

            if (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a") == "new")
            {
                albumID = LegacyDb.album_save(null, this.PageContext.PageUserID, this.txtTitle.Text, null).ToString();
            }
            else
            {
                LegacyDb.album_save(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a"), null, this.txtTitle.Text, null);
            }

            YafBuildLink.Redirect(ForumPages.cp_editalbumimages, "a={0}", albumID);
        }
예제 #3
0
        /// <summary>
        /// The change album title.
        /// </summary>
        /// <param name="albumId">
        /// The album id.
        /// </param>
        /// <param name="newTitle">
        /// The New title.
        /// </param>
        /// <returns>
        /// the return object.
        /// </returns>
        public static ReturnClass ChangeAlbumTitle(int albumId, [NotNull] string newTitle)
        {
            // load the DB so YafContext can work...
            CodeContracts.VerifyNotNull(newTitle, "newTitle");

            YafContext.Current.Get <StartupInitializeDb>().Run();

            // newTitle = System.Web.HttpUtility.HtmlEncode(newTitle);
            LegacyDb.album_save(albumId, null, newTitle, null);

            var returnObject = new ReturnClass {
                NewTitle = newTitle
            };

            returnObject.NewTitle = (newTitle == string.Empty)
                                        ? YafContext.Current.Get <ILocalization>().GetText("ALBUM", "ALBUM_CHANGE_TITLE")
                                        : newTitle;
            returnObject.Id = "0{0}".FormatWith(albumId.ToString());
            return(returnObject);
        }
예제 #4
0
        /// <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);
            }
        }