Ejemplo n.º 1
0
        /// <summary>
        /// The albums tab is visible.
        /// </summary>
        /// <returns>
        /// The true if albums tab should be visible.
        /// </returns>
        protected bool AlbumsTabIsVisible()
        {
            int albumUser = this.PageContext.PageUserID;

            if (this.PageContext.IsAdmin && this.UserId > 0)
            {
                albumUser = this.UserId;
            }

            // Add check if Albums Tab is visible
            if (!this.PageContext.IsGuest && this.Get <YafBoardSettings>().EnableAlbum)
            {
                int albumCount = LegacyDb.album_getstats(albumUser, null)[0];

                // Check if the user already has albums.
                if (albumCount > 0)
                {
                    return(true);
                }

                // If this is the album owner we show him the tab, else it should be hidden
                if ((albumUser == this.PageContext.PageUserID) || this.PageContext.IsAdmin)
                {
                    // Check if a user have permissions to have albums, even if he has no albums at all.
                    var usrAlbums =
                        LegacyDb.user_getalbumsdata(albumUser, YafContext.Current.PageBoardID)
                        .GetFirstRowColumnAsValue <int?>("UsrAlbums", null);

                    if (usrAlbums.HasValue && usrAlbums > 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// the page load event.
        /// </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 Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.Get <YafBoardSettings>().EnableAlbum)
            {
                YafBuildLink.AccessDenied();
            }

            if (this.IsPostBack)
            {
                return;
            }

            DataTable sigData = LegacyDb.user_getalbumsdata(this.PageContext.PageUserID, YafContext.Current.PageBoardID);

            var usrAlbumsAllowed = sigData.GetFirstRowColumnAsValue <int?>("UsrAlbums", null);

            int[] albumSize = LegacyDb.album_getstats(this.PageContext.PageUserID, null);
            int   userID;

            switch (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a"))
            {
            // A new album is being created. check the permissions.
            case "new":

                // Is album feature enabled?
                if (!this.Get <YafBoardSettings>().EnableAlbum)
                {
                    YafBuildLink.AccessDenied();
                }

                // Has the user created maximum number of albums?
                if (usrAlbumsAllowed.HasValue && usrAlbumsAllowed > 0)
                {
                    // Albums count. If we reached limit then we go to info page.
                    if (usrAlbumsAllowed > 0 && (albumSize[0] >= usrAlbumsAllowed))
                    {
                        YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                    }
                }

                /* if (this.Get<YafBoardSettings>().AlbumsMax > 0 &&
                 *                  albumSize[0] > this.Get<YafBoardSettings>().AlbumsMax - 1)
                 *        {
                 *            YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                 *        }*/
                userID = this.PageContext.PageUserID;
                break;

            default:
                userID =
                    LegacyDb.album_list(
                        null, Security.StringToLongOrRedirect(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a")))
                    .Rows[0]["UserID"].ToType <int>();

                if (userID != this.PageContext.PageUserID)
                {
                    YafBuildLink.AccessDenied();
                }

                break;
            }

            var displayName = YafContext.Current.Get <YafBoardSettings>().EnableDisplayName
                                  ? UserMembershipHelper.GetDisplayNameFromID(userID)
                                  : UserMembershipHelper.GetUserNameFromID(userID);

            // Add the page links.
            this.PageLinks.AddRoot();
            this.PageLinks.AddLink(
                displayName,
                YafBuildLink.GetLink(ForumPages.profile, "u={0}&name={1}", userID.ToString(), displayName));
            this.PageLinks.AddLink(
                this.GetText("ALBUMS"), YafBuildLink.GetLink(ForumPages.albums, "u={0}", userID.ToString()));
            this.PageLinks.AddLink(this.GetText("TITLE"), string.Empty);

            this.Back.Text   = this.GetText("BACK");
            this.Upload.Text = this.GetText("UPLOAD");

            this.BindData();

            var usrAlbumImagesAllowed = sigData.GetFirstRowColumnAsValue <int?>("UsrAlbumImages", null);

            // Has the user uploaded maximum number of images?
            // vzrus: changed for DB check The default number of album images is 0. In the case albums are disabled.
            if (usrAlbumImagesAllowed.HasValue && usrAlbumImagesAllowed > 0)
            {
                if (this.List.Items.Count >= usrAlbumImagesAllowed)
                {
                    this.uploadtitletr.Visible = false;
                    this.selectfiletr.Visible  = false;
                }
                else
                {
                    this.uploadtitletr.Visible = true;
                    this.selectfiletr.Visible  = true;
                }

                this.imagesInfo.Text = this.GetTextFormatted(
                    "IMAGES_INFO", this.List.Items.Count, usrAlbumImagesAllowed, this.Get <YafBoardSettings>().AlbumImagesSizeMax / 1024);
            }
            else
            {
                this.uploadtitletr.Visible = false;
                this.selectfiletr.Visible  = false;
            }
        }