/// <summary>
    /// Handles delete button action - deletes user favorite.
    /// </summary>
    protected void btnDelete_OnCommand(object sender, CommandEventArgs e)
    {
        // Check permissions
        if (!IsAvailable(ForumContext.CurrentForum, ForumActionType.Attachment))
        {
            ShowError(GetString("ForumNewPost.PermissionDenied"));
            return;
        }

        if (e.CommandName == "delete")
        {
            int attachmentId = ValidationHelper.GetInteger(e.CommandArgument, 0);

            // Get forum attachment info
            ForumAttachmentInfo fai = ForumAttachmentInfoProvider.GetForumAttachmentInfo(attachmentId);
            if (fai != null)
            {
                // Delete attachment
                ForumAttachmentInfoProvider.DeleteForumAttachmentInfo(fai);
            }

            //Reload page
            URLHelper.Redirect(RequestContext.CurrentURL);
        }
    }
Beispiel #2
0
    /// <summary>
    /// Upload click handler.
    /// </summary>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.forums", PERMISSION_MODIFY))
        {
            return;
        }

        if ((upload.HasFile) && (PostInfo != null))
        {
            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(upload.FileName, SiteContext.CurrentSiteName))
            {
                ShowError(GetString("ForumAttachment.AttachmentIsNotAllowed"));
                return;
            }

            ForumInfo fi = ForumInfoProvider.GetForumInfo(PostInfo.PostForumID);
            if (fi != null)
            {
                ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
                if (fgi != null)
                {
                    ForumAttachmentInfo fai = new ForumAttachmentInfo(upload.PostedFile, 0, 0, fi.ForumImageMaxSideSize);
                    fai.AttachmentPostID = PostInfo.PostId;
                    fai.AttachmentSiteID = fgi.GroupSiteID;
                    ForumAttachmentInfoProvider.SetForumAttachmentInfo(fai);

                    ReloadAttachmentData(PostInfo.PostId);
                    UniGrid.ReloadData();
                }
            }
        }
    }
Beispiel #3
0
    /// <summary>
    /// Upload click hadler.
    /// </summary>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.forums", CMSAdminControl.PERMISSION_MODIFY))
        {
            return;
        }

        if ((upload.HasFile) && (this.PostInfo != null))
        {
            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(upload.FileName, CMSContext.CurrentSiteName))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ForumAttachment.AttachmentIsNotAllowed");
                return;
            }

            ForumInfo fi = ForumInfoProvider.GetForumInfo(this.PostInfo.PostForumID);
            if (fi != null)
            {
                ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
                if (fgi != null)
                {
                    ForumAttachmentInfo fai = new ForumAttachmentInfo(upload.PostedFile, 0, 0, 0);
                    fai.AttachmentPostID = this.PostInfo.PostId;
                    fai.AttachmentSiteID = fgi.GroupSiteID;
                    ForumAttachmentInfoProvider.SetForumAttachmentInfo(fai);

                    ReloadAttachmentData(this.PostInfo.PostId);
                    UniGrid.ReloadData();
                }
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// Returns the output data dependency based on the given attachment record.
    /// </summary>
    /// <param name="mi">ForumAttachmentInfo object</param>
    protected CacheDependency GetOutputDataDependency(ForumAttachmentInfo fi)
    {
        if (fi == null)
        {
            return(null);
        }

        return(CacheHelper.GetCacheDependency(fi.GetDependencyCacheKeys()));
    }
    /// <summary>
    /// Handles file upload.
    /// </summary>
    protected void btnUpload_OnClick(object sender, EventArgs e)
    {
        if (ForumContext.CurrentForum == null)
        {
            return;
        }

        // Check permissions
        if (!this.IsAvailable(ForumContext.CurrentForum, ForumActionType.Attachment))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("ForumNewPost.PermissionDenied");
            return;
        }

        if (fileUpload.HasFile)
        {
            // Check max attachment size
            if ((ForumContext.CurrentForum.ForumAttachmentMaxFileSize > 0) && ((fileUpload.PostedFile.InputStream.Length / 1024) >= ForumContext.CurrentForum.ForumAttachmentMaxFileSize))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ForumAttachment.AttachmentIsTooLarge");
                return;
            }

            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(fileUpload.FileName, this.SiteName))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ForumAttachment.AttachmentIsNotAllowed");
                return;
            }

            ForumAttachmentInfo attachmentInfo = new ForumAttachmentInfo(fileUpload.PostedFile, 0, 0, ForumContext.CurrentForum.ForumImageMaxSideSize);
            attachmentInfo.AttachmentPostID = ForumContext.CurrentPost.PostId;
            ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(ForumContext.CurrentForum.ForumGroupID);
            if (fgi != null)
            {
                attachmentInfo.AttachmentSiteID = fgi.GroupSiteID;

                //Save to DB
                ForumAttachmentInfoProvider.SetForumAttachmentInfo(attachmentInfo);
                DataSet ds = ForumAttachmentInfoProvider.GetForumAttachments(ForumContext.CurrentPost.PostId, false);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    listAttachment.DataSource = ds;
                    listAttachment.DataBind();
                    plcListHeader.Visible = true;
                }
            }
        }
    }
    /// <summary>
    /// Processes the specified file.
    /// </summary>
    /// <param name="fileGuid">File guid</param>
    protected void ProcessFile(Guid fileGuid)
    {
        // Get the file
        ForumAttachmentInfo fileInfo = ForumAttachmentInfoProvider.GetForumAttachmentInfoWithoutBinary(fileGuid, CMSContext.CurrentSiteName);

        if (fileInfo != null)
        {
            #region "Security"

            // Indicates whether current user is granted to see this attachment
            bool attachmentAllowed = false;

            // Get forum
            ForumInfo fi = ForumInfoProvider.GetForumInfo(fileInfo.AttachmentForumID);
            if (fi != null)
            {
                // Check acess
                if (ForumViewer.CheckPermission("AccessToForum", SecurityHelper.GetSecurityAccessEnum(fi.ForumAccess, 6), fi.ForumGroupID, fi.ForumID))
                {
                    attachmentAllowed = true;
                }
            }

            // If attachment is not allowed for current user, redirect to the access denied page
            if (!attachmentAllowed)
            {
                URLHelper.Redirect(URLRewriter.AccessDeniedPageURL(CurrentSiteName));
            }

            #endregion


            bool resizeImage = (ImageHelper.IsMimeImage(fileInfo.AttachmentMimeType) &&
                                ForumAttachmentInfoProvider.CanResizeImage(fileInfo, Width, Height, MaxSideSize));

            // Get the data
            if ((outputFile == null) || (outputFile.ForumAttachment == null))
            {
                outputFile             = new CMSOutputForumAttachment(fileInfo, fileInfo.AttachmentBinary);
                outputFile.Width       = Width;
                outputFile.Height      = Height;
                outputFile.MaxSideSize = MaxSideSize;
                outputFile.Resized     = resizeImage;
            }
        }
    }
    /// <summary>
    /// Processes the file.
    /// </summary>
    protected void ProcessFile()
    {
        if (fileGuid == Guid.Empty)
        {
            return;
        }

        // Get the file
        ForumAttachmentInfo fileInfo = ForumAttachmentInfoProvider.GetForumAttachmentInfoWithoutBinary(fileGuid, SiteContext.CurrentSiteName);

        if (fileInfo == null)
        {
            return;
        }

        // Check forum access
        var forum = ForumInfoProvider.GetForumInfo(fileInfo.AttachmentForumID);

        if ((forum == null) || !ForumViewer.CheckPermission("AccessToForum", SecurityHelper.GetSecurityAccessEnum(forum.ForumAccess, 6), forum.ForumGroupID, forum.ForumID, CurrentUser))
        {
            // If attachment is not allowed for current user, redirect to the access denied page
            URLHelper.Redirect(PageSecurityHelper.AccessDeniedPageURL(CurrentSiteName));
        }

        bool resizeImage = (ImageHelper.IsMimeImage(fileInfo.AttachmentMimeType) && ForumAttachmentInfoProvider.CanResizeImage(fileInfo, Width, Height, MaxSideSize));

        // Get the data
        if ((outputFile == null) || (outputFile.ForumAttachment == null))
        {
            outputFile             = new CMSOutputForumAttachment(fileInfo, fileInfo.AttachmentBinary);
            outputFile.Width       = Width;
            outputFile.Height      = Height;
            outputFile.MaxSideSize = MaxSideSize;
            outputFile.Resized     = resizeImage;
        }
    }
    /// <summary>
    /// Returns the output data dependency based on the given attachment record.
    /// </summary>
    /// <param name="fi">ForumAttachmentInfo object</param>
    protected CMSCacheDependency GetOutputDataDependency(ForumAttachmentInfo fi)
    {
        if (fi == null)
        {
            return null;
        }

        return CacheHelper.GetCacheDependency(fi.GetDependencyCacheKeys());
    }
    /// <summary>
    /// Upload click handler.
    /// </summary>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.forums", PERMISSION_MODIFY))
        {
            return;
        }

        if ((upload.HasFile) && (PostInfo != null))
        {
            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(upload.FileName, SiteContext.CurrentSiteName))
            {
                ShowError(GetString("ForumAttachment.AttachmentIsNotAllowed"));
                return;
            }

            ForumInfo fi = ForumInfoProvider.GetForumInfo(PostInfo.PostForumID);
            if (fi != null)
            {
                ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
                if (fgi != null)
                {
                    ForumAttachmentInfo fai = new ForumAttachmentInfo(upload.PostedFile, 0, 0, fi.ForumImageMaxSideSize);
                    fai.AttachmentPostID = PostInfo.PostId;
                    fai.AttachmentSiteID = fgi.GroupSiteID;
                    ForumAttachmentInfoProvider.SetForumAttachmentInfo(fai);

                    ReloadAttachmentData(PostInfo.PostId);
                    UniGrid.ReloadData();
                }
            }
        }
    }
    /// <summary>
    /// Handles file upload.
    /// </summary>
    protected void btnUpload_OnClick(object sender, EventArgs e)
    {
        if (ForumContext.CurrentForum == null)
        {
            return;
        }

        // Check permissions
        if (!IsAvailable(ForumContext.CurrentForum, ForumActionType.Attachment))
        {
            ShowError(GetString("ForumNewPost.PermissionDenied"));
            return;
        }

        if (fileUpload.HasFile)
        {
            // Check max attachment size
            if ((ForumContext.CurrentForum.ForumAttachmentMaxFileSize > 0) && ((fileUpload.PostedFile.InputStream.Length / 1024) >= ForumContext.CurrentForum.ForumAttachmentMaxFileSize))
            {
                ShowError(GetString("ForumAttachment.AttachmentIsTooLarge"));
                return;
            }

            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(fileUpload.FileName, SiteName))
            {
                ShowError(GetString("ForumAttachment.AttachmentIsNotAllowed"));
                return;
            }

            ForumAttachmentInfo attachmentInfo = new ForumAttachmentInfo(fileUpload.PostedFile, 0, 0, ForumContext.CurrentForum.ForumImageMaxSideSize);
            attachmentInfo.AttachmentPostID = ForumContext.CurrentPost.PostId;
            ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(ForumContext.CurrentForum.ForumGroupID);
            if (fgi != null)
            {
                attachmentInfo.AttachmentSiteID = fgi.GroupSiteID;

                //Save to DB
                ForumAttachmentInfoProvider.SetForumAttachmentInfo(attachmentInfo);
                DataSet ds = ForumAttachmentInfoProvider.GetForumAttachments(ForumContext.CurrentPost.PostId, false);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    listAttachment.DataSource = ds;
                    listAttachment.DataBind();
                    plcListHeader.Visible = true;
                }
            }
        }
    }
        /// <summary>
        /// Provides operations necessary to create and store new cms file.
        /// </summary>
        /// <param name="args">Upload arguments.</param>
        /// <param name="context">HttpContext instance.</param>
        private void HandleForumUpload(UploaderHelper args, HttpContext context)
        {
            ForumInfo fi = null;

            try
            {
                args.IsExtensionAllowed();

                if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.forums", CMSAdminControl.PERMISSION_MODIFY))
                {
                    throw new Exception("Current user is not granted with modify permission per 'cms.forums' resource.");
                }

                fi = ForumInfoProvider.GetForumInfo(args.ForumArgs.PostForumID);
                if (fi != null)
                {
                    ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
                    if (fgi != null)
                    {
                        ForumAttachmentInfo fai = new ForumAttachmentInfo(args.FilePath, 0, 0, 0)
                        {
                            AttachmentPostID = args.ForumArgs.PostID,
                            AttachmentSiteID = fgi.GroupSiteID
                        };
                        ForumAttachmentInfoProvider.SetForumAttachmentInfo(fai);
                    }
                }
            }
            catch (Exception ex)
            {
                args.Message = ex.Message;

                // Log the error
                EventLogProvider.LogException("MultiFileUploader", "UPLOADFORUM", ex);
            }
            finally
            {
                if (!string.IsNullOrEmpty(args.AfterSaveJavascript))
                {
                    args.AfterScript = String.Format(@"
                    if (window.{0} != null) {{
                        window.{0}()
                    }} else if ((window.parent != null) && (window.parent.{0} != null)) {{
                        window.parent.{0}() 
                    }}", args.AfterSaveJavascript);
                }
                else
                {
                    args.AfterScript = String.Format(@"
                    if (window.InitRefresh_{0})
                    {{
                        window.InitRefresh_{0}('{1}', false, false);
                    }}
                    else {{ 
                        if ('{1}' != '') {{
                            alert('{1}');
                        }}
                    }}", args.ParentElementID, ScriptHelper.GetString(args.Message.Trim(), false));
                }

                args.AddEventTargetPostbackReference();
                context.Response.Write(args.AfterScript);
                context.Response.Flush();
            }
        }
Beispiel #12
0
    /// <summary>
    /// Upload click hadler.
    /// </summary>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.forums", CMSAdminControl.PERMISSION_MODIFY))
        {
            return;
        }

        if ((upload.HasFile) && (this.PostInfo != null))
        {
            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(upload.FileName, CMSContext.CurrentSiteName))
            {
                lblError.Visible = true;
                lblError.Text = GetString("ForumAttachment.AttachmentIsNotAllowed");
                return;
            }

            ForumInfo fi = ForumInfoProvider.GetForumInfo(this.PostInfo.PostForumID);
            if (fi != null)
            {
                ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
                if (fgi != null)
                {
                    ForumAttachmentInfo fai = new ForumAttachmentInfo(upload.PostedFile, 0, 0, 0);
                    fai.AttachmentPostID = this.PostInfo.PostId;
                    fai.AttachmentSiteID = fgi.GroupSiteID;
                    ForumAttachmentInfoProvider.SetForumAttachmentInfo(fai);

                    ReloadAttachmentData(this.PostInfo.PostId);
                    UniGrid.ReloadData();
                }
            }
        }
    }
        /// <summary>
        /// Provides operations necessary to create and store new cms file.
        /// </summary>
        /// <param name="args">Upload arguments.</param>
        /// <param name="context">HttpContext instance.</param>
        private void HandleForumUpload(UploaderHelper args, HttpContext context)
        {
            ForumInfo fi = null;

            try
            {
                args.IsExtensionAllowed();

                if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.forums", CMSAdminControl.PERMISSION_MODIFY))
                {
                    throw new Exception("Current user is not granted with modify permission per 'cms.forums' resource.");
                }

                fi = ForumInfoProvider.GetForumInfo(args.ForumArgs.PostForumID);
                if (fi != null)
                {
                    ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
                    if (fgi != null)
                    {
                        ForumAttachmentInfo fai = new ForumAttachmentInfo(args.FilePath, 0, 0, 0)
                                                      {
                                                          AttachmentPostID = args.ForumArgs.PostID,
                                                          AttachmentSiteID = fgi.GroupSiteID
                                                      };
                        ForumAttachmentInfoProvider.SetForumAttachmentInfo(fai);
                    }
                }
            }
            catch (Exception ex)
            {
                args.Message = ex.Message;

                // Log the error
                EventLogProvider.LogException("MultiFileUploader", "UPLOADFORUM", ex);
            }
            finally
            {
                if (!string.IsNullOrEmpty(args.AfterSaveJavascript))
                {
                    args.AfterScript = String.Format(@"
                    if (window.{0} != null) {{
                        window.{0}()
                    }} else if ((window.parent != null) && (window.parent.{0} != null)) {{
                        window.parent.{0}()
                    }}", args.AfterSaveJavascript);
                }
                else
                {
                    args.AfterScript = String.Format(@"
                    if (window.InitRefresh_{0})
                    {{
                        window.InitRefresh_{0}('{1}', false, false);
                    }}
                    else {{
                        if ('{1}' != '') {{
                            alert('{1}');
                        }}
                    }}", args.ParentElementID, ScriptHelper.GetString(args.Message.Trim(), false));
                }

                args.AddEventTargetPostbackReference();
                context.Response.Write(args.AfterScript);
                context.Response.Flush();
            }
        }