예제 #1
0
        public void ProcessRequest(HttpContext context)
        {
            base.Initialize(context);

            if (!UserCanEditModule(ModuleId, Blog.FeatureGuid))
            {
                log.Info("User has no edit permission so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (CurrentSite == null)
            {
                log.Info("CurrentSite is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (CurrentUser == null)
            {
                log.Info("CurrentUser is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (FileSystem == null)
            {
                log.Info("FileSystem is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (Request.Files.Count == 0)
            {
                log.Info("Posted File Count is zero so returning 404");
                Response.StatusCode = 404;
                return;
            }

            if (Request.Files.Count > BlogConfiguration.MaxAttachmentsToUploadAtOnce)
            {
                log.Info("Posted File Count is higher than allowed so returning 404");
                Response.StatusCode = 404;
                return;
            }

            itemId = WebUtils.ParseInt32FromQueryString("ItemID", itemId);

            if (itemId == -1)
            {
                log.Info("No ItemID provided so returning 404");
                Response.StatusCode = 404;
                return;
            }

            module = GetModule(ModuleId, Blog.FeatureGuid);

            if (module == null)
            {
                log.Info("Module is null so returning 404");
                Response.StatusCode = 404;
                return;
            }

            blog = new Blog(itemId);
            if (blog.ModuleId != ModuleId)
            {
                log.Info("Invalid ItemID for module so returning 404");
                Response.StatusCode = 404;
                return;
            }

            Hashtable moduleSettings = ModuleSettings.GetModuleSettings(ModuleId);

            config = new BlogConfiguration(moduleSettings);

            context.Response.ContentType = "text/plain";//"application/json";
            var r = new System.Collections.Generic.List <UploadFilesResult>();
            JavaScriptSerializer js = new JavaScriptSerializer();

            SiteUtils.EnsureFileAttachmentFolder(CurrentSite);
            string upLoadPath = SiteUtils.GetFileAttachmentUploadPath();

            for (int f = 0; f < Request.Files.Count; f++)
            {
                HttpPostedFile file = Request.Files[f];

                string ext = System.IO.Path.GetExtension(file.FileName);

                if (!SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.AllowedMediaFileExtensions))
                {
                    log.Info("file extension was " + ext + " so discarding file " + file.FileName);

                    r.Add(new UploadFilesResult()
                    {
                        Name         = file.FileName,
                        Length       = file.ContentLength,
                        Type         = file.ContentType,
                        ErrorMessage = string.Format(
                            CultureInfo.InvariantCulture,
                            GalleryResources.InvalidUploadExtensionFormat,
                            file.FileName,
                            WebConfigSettings.AllowedMediaFileExtensions.Replace("|", " "))
                    });

                    continue;
                }

                string mimeType = IOHelper.GetMimeType(ext).ToLower();

                FileAttachment a = new FileAttachment();
                a.CreatedBy      = CurrentUser.UserGuid;
                a.FileName       = System.IO.Path.GetFileName(file.FileName);
                a.ServerFileName = blog.ItemId.ToInvariantString() + a.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                a.ModuleGuid     = blog.ModuleGuid;
                a.SiteGuid       = CurrentSite.SiteGuid;
                a.ItemGuid       = blog.BlogGuid;
                a.ContentLength  = file.ContentLength;
                a.ContentType    = mimeType;

                a.Save();

                string destPath = upLoadPath + a.ServerFileName;

                using (Stream s = file.InputStream)
                {
                    FileSystem.SaveFile(destPath, s, mimeType, true);
                }

                r.Add(new UploadFilesResult()
                {
                    //Thumbnail_url =
                    Name   = a.FileName,
                    Length = file.ContentLength,
                    Type   = mimeType
                });

                if (WebConfigSettings.LogAllFileServiceRequests)
                {
                    string userName = "******";
                    if (CurrentUser != null)
                    {
                        userName = CurrentUser.Name;
                    }
                    log.Info("File " + file.FileName + " uploaded by " + userName + " as a media attachment in the Blog");
                }
            }

            var uploadedFiles = new
            {
                files = r.ToArray()
            };

            var jsonObj = js.Serialize(uploadedFiles);

            context.Response.Write(jsonObj.ToString());
        }
예제 #2
0
        private void LoadSettings()
        {
            pageID       = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId     = WebUtils.ParseInt32FromQueryString("mid", -1);
            categoryId   = WebUtils.ParseInt32FromQueryString("cat", categoryId);
            siteSettings = CacheHelper.GetCurrentSiteSettings();

            // newer implementation combines params as p=pageid~moduleid~categoryid
            string f = WebUtils.ParseStringFromQueryString("p", string.Empty);

            if ((f.Length > 0) && (f.Contains("~")))
            {
                List <string> parms = f.SplitOnCharAndTrim('~');

                if (parms.Count >= 1)
                {
                    int.TryParse(parms[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out pageID);
                }

                if (parms.Count >= 2)
                {
                    int.TryParse(parms[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out moduleId);
                }

                if (parms.Count >= 3)
                {
                    int.TryParse(parms[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out categoryId);
                }
            }


            securityBypassGuid = WebUtils.ParseGuidFromQueryString("g", securityBypassGuid);
            attachmentBaseUrl  = SiteUtils.GetFileAttachmentUploadPath();
            pageSettings       = CacheHelper.GetPage(pageID);
            module             = GetModule();

            if ((moduleId == -1) || (module == null))
            {
                return;
            }

            bool bypassPageSecurity = false;

            if ((securityBypassGuid != Guid.Empty) && (securityBypassGuid == WebConfigSettings.InternalFeedSecurityBypassKey))
            {
                bypassPageSecurity = true;
            }

            if (
                (bypassPageSecurity) ||
                (WebUser.IsInRoles(pageSettings.AuthorizedRoles)) ||
                (WebUser.IsInRoles(module.ViewRoles))
                )
            {
                canView = true;
            }

            if (!canView)
            {
                return;
            }

            if (WebConfigSettings.UseFolderBasedMultiTenants)
            {
                navigationSiteRoot = SiteUtils.GetNavigationSiteRoot();
                blogBaseUrl        = navigationSiteRoot;
                imageSiteRoot      = WebUtils.GetSiteRoot();
                cssBaseUrl         = imageSiteRoot;
            }
            else
            {
                navigationSiteRoot = WebUtils.GetHostRoot();
                blogBaseUrl        = SiteUtils.GetNavigationSiteRoot();
                imageSiteRoot      = navigationSiteRoot;
                cssBaseUrl         = WebUtils.GetSiteRoot();
            }

            moduleSettings = ModuleSettings.GetModuleSettings(moduleId);
            config         = new BlogConfiguration(moduleSettings);

            if (config.FeedIsDisabled)
            {
                canView = false;
            }

            if ((config.FeedburnerFeedUrl.Length > 0) && (config.FeedburnerFeedUrl.StartsWith("http")) && (BlogConfiguration.UseRedirectForFeedburner))
            {
                shouldRedirectToFeedburner = true;
                if ((Request.UserAgent != null) && (Request.UserAgent.Contains("FeedBurner")))
                {
                    shouldRedirectToFeedburner = false; // don't redirect if the feedburner bot is reading the feed
                }

                Guid redirectBypassToken = WebUtils.ParseGuidFromQueryString("r", Guid.Empty);
                if (redirectBypassToken == Global.FeedRedirectBypassToken)
                {
                    shouldRedirectToFeedburner = false; // allows time for user to subscribe to autodiscovery links without redirecting
                }
            }
        }
예제 #3
0
        protected virtual void LoadSettings()
        {
            siteSettings     = CacheHelper.GetCurrentSiteSettings();
            siteId           = siteSettings.SiteId;
            currentUser      = SiteUtils.GetCurrentSiteUser();
            TimeOffset       = SiteUtils.GetUserTimeOffset();
            timeZone         = SiteUtils.GetUserTimeZone();
            GmapApiKey       = SiteUtils.GetGmapApiKey();
            addThisAccountId = siteSettings.AddThisDotComUsername;

            if (blogConfig.AddThisAccountId.Length > 0)
            {
                addThisAccountId = blogConfig.AddThisAccountId;
            }

            pageNumber        = WebUtils.ParseInt32FromQueryString("pagenumber", pageNumber);
            categoryId        = WebUtils.ParseInt32FromQueryString("cat", categoryId);
            Month             = WebUtils.ParseInt32FromQueryString("month", Month);
            Year              = WebUtils.ParseInt32FromQueryString("year", Year);
            attachmentBaseUrl = SiteUtils.GetFileAttachmentUploadPath();

            //if (Page is mojoBasePage)
            //{
            //	basePage = Page as mojoBasePage;
            //	module = basePage.GetModule(moduleId, config.FeatureGuid);

            //}

            module = new Module(moduleId);

            //if (module == null)
            //{
            //	return;
            //}

            CalendarDate = WebUtils.ParseDateFromQueryString("blogdate", DateTime.UtcNow).Date;

            if (CalendarDate > DateTime.UtcNow.Date)
            {
                CalendarDate = DateTime.UtcNow.Date;
            }

            if (blogConfig.UseExcerpt && !blogConfig.GoogleMapIncludeWithExcerpt)
            {
                ShowGoogleMap = false;
            }

            if (blogConfig.UseExcerpt)
            {
                EnableContentRating = false;
            }

            if (blogConfig.DisqusSiteShortName.Length > 0)
            {
                DisqusSiteShortName = blogConfig.DisqusSiteShortName;
            }
            else
            {
                DisqusSiteShortName = siteSettings.DisqusSiteShortName;
            }

            if (blogConfig.IntenseDebateAccountId.Length > 0)
            {
                IntenseDebateAccountId = blogConfig.IntenseDebateAccountId;
            }
            else
            {
                IntenseDebateAccountId = siteSettings.IntenseDebateAccountId;
            }

            ShowTweetThisLink     = blogConfig.ShowTweetThisLink && !blogConfig.UseExcerpt;
            ShowPlusOneButton     = blogConfig.ShowPlusOneButton && !blogConfig.UseExcerpt;
            UseFacebookLikeButton = blogConfig.UseFacebookLikeButton && !blogConfig.UseExcerpt;

            pageSize = config.ItemsPerPage;

            useFriendlyUrls = BlogConfiguration.UseFriendlyUrls(moduleId);

            if (!WebConfigSettings.UseUrlReWriting)
            {
                useFriendlyUrls = false;
            }

            if (WebConfigSettings.UseFolderBasedMultiTenants)
            {
                navigationSiteRoot = SiteUtils.GetNavigationSiteRoot();
                imageSiteRoot      = WebUtils.GetSiteRoot();
            }
            else
            {
                navigationSiteRoot = WebUtils.GetHostRoot();
                imageSiteRoot      = navigationSiteRoot;
            }
        }
예제 #4
0
        protected virtual void LoadSettings()
        {
            siteSettings     = CacheHelper.GetCurrentSiteSettings();
            SiteId           = siteSettings.SiteId;
            currentUser      = SiteUtils.GetCurrentSiteUser();
            TimeOffset       = SiteUtils.GetUserTimeOffset();
            timeZone         = SiteUtils.GetUserTimeZone();
            GmapApiKey       = SiteUtils.GetGmapApiKey();
            addThisAccountId = siteSettings.AddThisDotComUsername;

            if (config.AddThisAccountId.Length > 0)
            {
                addThisAccountId = config.AddThisAccountId;
            }

            pageNumber        = WebUtils.ParseInt32FromQueryString("pagenumber", pageNumber);
            categoryId        = WebUtils.ParseInt32FromQueryString("cat", categoryId);
            Month             = WebUtils.ParseInt32FromQueryString("month", Month);
            Year              = WebUtils.ParseInt32FromQueryString("year", Year);
            attachmentBaseUrl = SiteUtils.GetFileAttachmentUploadPath();

            if (Page is mojoBasePage)
            {
                basePage = Page as mojoBasePage;
                module   = basePage.GetModule(ModuleId, Blog.FeatureGuid);
            }

            if (module == null)
            {
                return;
            }

            MaxAllowedGravatarRating = SiteUtils.GetMaxAllowedGravatarRating();
            UserNameTooltipFormat    = displaySettings.AvatarUserNameTooltipFormat;

            switch (siteSettings.AvatarSystem)
            {
            case "gravatar":
                allowGravatars = true;
                disableAvatars = false;
                break;

            case "internal":
                allowGravatars = false;
                disableAvatars = false;
                break;

            case "none":
            default:
                allowGravatars = false;
                disableAvatars = true;
                break;
            }

            //if (!config.ShowAuthorAvatar) { disableAvatars = true; }

            if (config.UseExcerpt && !displaySettings.ShowAvatarWithExcerpt)
            {
                disableAvatars = true;
            }

            CalendarDate = WebUtils.ParseDateFromQueryString("blogdate", DateTime.UtcNow).Date;

            if (CalendarDate > DateTime.UtcNow.Date)
            {
                CalendarDate = DateTime.UtcNow.Date;
            }

            if ((config.UseExcerpt) && (!config.GoogleMapIncludeWithExcerpt))
            {
                ShowGoogleMap = false;
            }

            EnableContentRating = config.EnableContentRating && !displaySettings.PostListDisableContentRating;

            if (config.UseExcerpt)
            {
                EnableContentRating = false;
            }

            //if (config.AddThisCustomBrand.Length > 0)
            //{
            //    addThisCustomBrand = config.AddThisCustomBrand;
            //}

            if (config.DisqusSiteShortName.Length > 0)
            {
                DisqusSiteShortName = config.DisqusSiteShortName;
            }
            else
            {
                DisqusSiteShortName = siteSettings.DisqusSiteShortName;
            }

            if (config.IntenseDebateAccountId.Length > 0)
            {
                IntenseDebateAccountId = config.IntenseDebateAccountId;
            }
            else
            {
                IntenseDebateAccountId = siteSettings.IntenseDebateAccountId;
            }

            Control cNav = Page.LoadControl("~/Blog/Controls/BlogNav.ascx");

            BlogNav nav = (BlogNav)cNav;

            nav.ModuleId      = ModuleId;
            nav.ModuleGuid    = module.ModuleGuid;
            nav.PageId        = PageId;
            nav.IsEditable    = IsEditable;
            nav.Config        = config;
            nav.SiteRoot      = SiteRoot;
            nav.ImageSiteRoot = ImageSiteRoot;

            TitleOnly             = config.TitleOnly || displaySettings.PostListForceTitleOnly;
            ShowTweetThisLink     = config.ShowTweetThisLink && !config.UseExcerpt;
            ShowPlusOneButton     = config.ShowPlusOneButton && !config.UseExcerpt;
            UseFacebookLikeButton = config.UseFacebookLikeButton && !config.UseExcerpt;
            useExcerpt            = config.UseExcerpt || displaySettings.PostListForceExcerptMode;
            pageSize      = config.PageSize;
            AllowComments = Config.AllowComments && ShowCommentCounts;

            //TODO: should we use separate settings for each displaymode?
            switch (DisplayMode)
            {
            case "ByCategory":
                if (displaySettings.CategoryListForceTitleOnly)
                {
                    TitleOnly = true;
                }

                if (displaySettings.CategoryListOverridePageSize > 0)
                {
                    pageSize = displaySettings.CategoryListOverridePageSize;
                }

                if (displaySettings.ArchiveViewHideFeedbackLink)
                {
                    AllowComments = false;
                }

                if (displaySettings.OverrideCategoryListItemHeadingElement.Length > 0)
                {
                    itemHeadingElement = displaySettings.OverrideCategoryListItemHeadingElement;
                }

                break;

            case "ByMonth":
                if (displaySettings.ArchiveListForceTitleOnly)
                {
                    TitleOnly = true;
                }

                if (displaySettings.ArchiveListOverridePageSize > 0)
                {
                    pageSize = displaySettings.ArchiveListOverridePageSize;
                }

                if (displaySettings.OverrideArchiveListItemHeadingElement.Length > 0)
                {
                    itemHeadingElement = displaySettings.OverrideArchiveListItemHeadingElement;
                }

                break;

            case "DescendingByDate":
            default:
                if (displaySettings.PostListOverridePageSize > 0)
                {
                    pageSize = displaySettings.PostListOverridePageSize;
                }

                if (displaySettings.OverrideListItemHeadingElement.Length > 0)
                {
                    itemHeadingElement = displaySettings.OverrideListItemHeadingElement;
                }

                break;
            }

            if (config.AllowComments)
            {
                if ((DisqusSiteShortName.Length > 0) && (config.CommentSystem == "disqus"))
                {
                    disqusFlag                      = "#disqus_thread";
                    disqus.SiteShortName            = DisqusSiteShortName;
                    disqus.RenderCommentCountScript = true;
                    nav.ShowCommentCount            = false;
                }

                if ((IntenseDebateAccountId.Length > 0) && (config.CommentSystem == "intensedebate"))
                {
                    ShowCommentCounts    = false;
                    nav.ShowCommentCount = false;
                }

                if (config.CommentSystem == "facebook")
                {
                    ShowCommentCounts    = false;
                    nav.ShowCommentCount = false;
                }
            }
            else
            {
                nav.ShowCommentCount = false;
            }

            bool showNav = false;

            if (
                config.ShowCalendar ||
                config.ShowArchives ||
                ((config.ShowFeedLinks == true && displaySettings.HideFeedLinks == false) ? true : false) ||
                config.ShowCategories ||
                config.ShowStatistics ||
                !string.IsNullOrWhiteSpace(config.UpperSidebar) ||
                !string.IsNullOrWhiteSpace(config.LowerSidebar)
                )
            {
                showNav = true;
            }

            divBlog.CssClass = displaySettings.ListViewCenterClass;

            if (showNav)
            {
                if (config.NavigationOnRight)
                {
                    phNavRight.Controls.Add(nav);
                    divBlog.CssClass += " " + displaySettings.ListViewCenterRightNavClass;
                }
                else
                {
                    phNavLeft.Controls.Add(nav);
                    divBlog.CssClass += " " + displaySettings.ListViewCenterLeftNavClass;
                }
            }
            else
            {
                divBlog.CssClass += " " + displaySettings.ListViewCenterNoNavClass;
            }

            if (displaySettings.PostListExtraCss.Length > 0)
            {
                divBlog.CssClass += " " + displaySettings.PostListExtraCss;
            }

            pnlLayoutRow.RenderId           = false;
            pnlLayoutRow.RenderContentsOnly = true;
            pnlLayoutRow.CssClass           = displaySettings.LayoutRowClass;

            if (showNav && displaySettings.LayoutRowRender)
            {
                pnlLayoutRow.RenderContentsOnly = false;
            }

            useFriendlyUrls = BlogConfiguration.UseFriendlyUrls(ModuleId);

            if (!WebConfigSettings.UseUrlReWriting)
            {
                useFriendlyUrls = false;
            }

            if (config.Copyright.Length > 0)
            {
                litCopyright.Text    = config.Copyright;
                pnlCopyright.Visible = true;
            }

            pnlCopyright.CssClass = displaySettings.CopyrightPanelClass;

            pnlPager.CssClass = displaySettings.PagerPanelClass;
        }
예제 #5
0
        protected virtual void LoadSettings()
        {
            siteSettings     = CacheHelper.GetCurrentSiteSettings();
            siteId           = siteSettings.SiteId;
            currentUser      = SiteUtils.GetCurrentSiteUser();
            TimeOffset       = SiteUtils.GetUserTimeOffset();
            timeZone         = SiteUtils.GetUserTimeZone();
            GmapApiKey       = SiteUtils.GetGmapApiKey();
            addThisAccountId = siteSettings.AddThisDotComUsername;

            if (blogConfig.AddThisAccountId.Length > 0)
            {
                addThisAccountId = blogConfig.AddThisAccountId;
            }

            pageNumber        = WebUtils.ParseInt32FromQueryString("pagenumber", pageNumber);
            categoryId        = WebUtils.ParseInt32FromQueryString("cat", categoryId);
            Month             = WebUtils.ParseInt32FromQueryString("month", Month);
            Year              = WebUtils.ParseInt32FromQueryString("year", Year);
            attachmentBaseUrl = SiteUtils.GetFileAttachmentUploadPath();

            if (Page is mojoBasePage)
            {
                basePage = Page as mojoBasePage;
                module   = basePage.GetModule(moduleId, config.FeatureGuid);
            }

            if (module == null)
            {
                return;
            }

            MaxAllowedGravatarRating = SiteUtils.GetMaxAllowedGravatarRating();

            switch (siteSettings.AvatarSystem)
            {
            case "gravatar":
                allowGravatars = true;
                disableAvatars = false;
                break;

            case "internal":
                allowGravatars = false;
                disableAvatars = false;
                break;

            case "none":
            default:
                allowGravatars = false;
                disableAvatars = true;
                break;
            }

            CalendarDate = WebUtils.ParseDateFromQueryString("blogdate", DateTime.UtcNow).Date;

            if (CalendarDate > DateTime.UtcNow.Date)
            {
                CalendarDate = DateTime.UtcNow.Date;
            }

            if ((blogConfig.UseExcerpt) && (!blogConfig.GoogleMapIncludeWithExcerpt))
            {
                ShowGoogleMap = false;
            }

            if (blogConfig.UseExcerpt)
            {
                EnableContentRating = false;
            }

            if (blogConfig.DisqusSiteShortName.Length > 0)
            {
                DisqusSiteShortName = blogConfig.DisqusSiteShortName;
            }
            else
            {
                DisqusSiteShortName = siteSettings.DisqusSiteShortName;
            }

            if (blogConfig.IntenseDebateAccountId.Length > 0)
            {
                IntenseDebateAccountId = blogConfig.IntenseDebateAccountId;
            }
            else
            {
                IntenseDebateAccountId = siteSettings.IntenseDebateAccountId;
            }


            ShowTweetThisLink     = blogConfig.ShowTweetThisLink && !blogConfig.UseExcerpt;
            ShowPlusOneButton     = blogConfig.ShowPlusOneButton && !blogConfig.UseExcerpt;
            UseFacebookLikeButton = blogConfig.UseFacebookLikeButton && !blogConfig.UseExcerpt;
            pageSize = blogConfig.PageSize;

            useFriendlyUrls = BlogConfiguration.UseFriendlyUrls(moduleId);
            if (!WebConfigSettings.UseUrlReWriting)
            {
                useFriendlyUrls = false;
            }
        }