예제 #1
0
        public static void Run([TimerTrigger("%CRON_EXPRESSION%")] TimerInfo myTimer, ILogger log)
        {
            //---------------------------------------------
            // HTMLを取得する
            //---------------------------------------------
            var repository = new HtmlRepository(__httpClient);
            var uri        = new Uri(Environment.GetEnvironmentVariable("MATTERMOST_WEBHOOK_URL"));

            //---------------------------------------------
            // HTMLを取得する
            //---------------------------------------------
            var parser = new TechCrunchPopularHtmlParserCreateService(repository).Create();

            //---------------------------------------------
            // 投稿するテキストを作成する
            //---------------------------------------------
            IMattermostText text = new PopularTechnologyText(parser);

            //---------------------------------------------
            // 投稿する
            //---------------------------------------------
            var service = new MattermostWebhookService(uri, text);
            var result  = service.Post();

            log.LogInformation($"HTTP Status: {(int)result.StatusCode} {result.ReasonPhrase}");
        }
예제 #2
0
        public void Test_Read_指定したURIのHTMLが取得できること()
        {
            var uri        = new Uri("https://tomoprogsample.com");
            var repository = new HtmlRepository(_client);
            var result     = repository.FindByUri(uri);

            Assert.AreEqual("html", result.ToString());
        }
예제 #3
0
        public override void DeleteContent(int moduleId, Guid moduleGuid)
        {
            ContentHistory.DeleteByContent(moduleGuid);
            ContentWorkflow.DeleteByModule(moduleGuid);
            HtmlRepository repository = new HtmlRepository();

            repository.DeleteByModule(moduleId);
        }
예제 #4
0
        public void InstallContent(Module module, string configInfo)
        {
            HtmlContent htmlContent = new HtmlContent();

            htmlContent.ModuleId = module.ModuleId;
            if (configInfo.StartsWith("~/"))
            {
                if (File.Exists(HostingEnvironment.MapPath(configInfo)))
                {
                    htmlContent.Body = File.ReadAllText(HostingEnvironment.MapPath(configInfo), Encoding.UTF8);
                }
            }
            else
            {
                htmlContent.Body = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentUICulture, configInfo);
            }

            htmlContent.ModuleGuid = module.ModuleGuid;

            SiteSettings siteSettings = new SiteSettings(module.SiteId);
            SiteUser     adminUser    = null;

            if (siteSettings.UseEmailForLogin)
            {
                adminUser = new SiteUser(siteSettings, "*****@*****.**");
                if (adminUser.UserId == -1)
                {
                    adminUser = null;
                }
            }
            else
            {
                adminUser = new SiteUser(siteSettings, "admin");
                if (adminUser.UserId == -1)
                {
                    adminUser = null;
                }
            }

            if (adminUser != null)
            {
                htmlContent.UserGuid        = adminUser.UserGuid;
                htmlContent.LastModUserGuid = adminUser.UserGuid;
            }

            HtmlRepository repository = new HtmlRepository();

            repository.Save(htmlContent);
        }
        public override void RebuildIndex(
            PageSettings pageSettings,
            string indexPath)
        {
            bool disableSearchIndex = ConfigHelper.GetBoolProperty("DisableSearchIndex", false);

            if (disableSearchIndex)
            {
                return;
            }

            if (pageSettings == null)
            {
                log.Error("pageSettings passed in to HtmlContentIndexBuilderProvider.RebuildIndex was null");
                return;
            }

            //don't index pending/unpublished pages
            if (pageSettings.IsPending)
            {
                return;
            }

            log.Info(Resource.HtmlContentFeatureName + " indexing page - " + pageSettings.PageName);

            try
            {
                Guid htmlFeatureGuid
                    = new Guid("881e4e00-93e4-444c-b7b0-6672fb55de10");
                ModuleDefinition htmlFeature
                    = new ModuleDefinition(htmlFeatureGuid);

                List <PageModule> pageModules
                    = PageModule.GetPageModulesByPage(pageSettings.PageId);

                HtmlRepository repository = new HtmlRepository();

                DataTable dataTable = repository.GetHtmlContentByPage(
                    pageSettings.SiteId,
                    pageSettings.PageId);

                foreach (DataRow row in dataTable.Rows)
                {
                    bool includeInSearch          = Convert.ToBoolean(row["IncludeInSearch"]);
                    bool excludeFromRecentContent = Convert.ToBoolean(row["ExcludeFromRecentContent"]);

                    IndexItem indexItem = new IndexItem();
                    indexItem.ExcludeFromRecentContent = excludeFromRecentContent;
                    indexItem.SiteId   = pageSettings.SiteId;
                    indexItem.PageId   = pageSettings.PageId;
                    indexItem.PageName = pageSettings.PageName;

                    string authorName      = row["CreatedByName"].ToString();
                    string authorFirstName = row["CreatedByFirstName"].ToString();
                    string authorLastName  = row["CreatedByLastName"].ToString();

                    if ((authorFirstName.Length > 0) && (authorLastName.Length > 0))
                    {
                        indexItem.Author = string.Format(CultureInfo.InvariantCulture,
                                                         Resource.FirstNameLastNameFormat, authorFirstName, authorLastName);
                    }
                    else
                    {
                        indexItem.Author = authorName;
                    }

                    if (!includeInSearch)
                    {
                        indexItem.RemoveOnly = true;
                    }

                    // generally we should not include the page meta because it can result in duplicate results
                    // one for each instance of html content on the page because they all use the smae page meta.
                    // since page meta should reflect the content of the page it is sufficient to just index the content
                    if (WebConfigSettings.IndexPageKeywordsWithHtmlArticleContent)
                    {
                        indexItem.PageMetaDescription = pageSettings.PageMetaDescription;
                        indexItem.PageMetaKeywords    = pageSettings.PageMetaKeyWords;
                    }

                    indexItem.ViewRoles       = pageSettings.AuthorizedRoles;
                    indexItem.ModuleViewRoles = row["ViewRoles"].ToString();
                    if (pageSettings.UseUrl)
                    {
                        if (pageSettings.UrlHasBeenAdjustedForFolderSites)
                        {
                            indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty);
                        }
                        else
                        {
                            indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty);
                        }
                        indexItem.UseQueryStringParams = false;
                    }
                    indexItem.FeatureId           = htmlFeatureGuid.ToString();
                    indexItem.FeatureName         = htmlFeature.FeatureName;
                    indexItem.FeatureResourceFile = htmlFeature.ResourceFile;

                    indexItem.ItemId      = Convert.ToInt32(row["ItemID"]);
                    indexItem.ModuleId    = Convert.ToInt32(row["ModuleID"]);
                    indexItem.ModuleTitle = row["ModuleTitle"].ToString();
                    indexItem.Title       = row["Title"].ToString();
                    // added the remove markup 2010-01-30 because some javascript strings like ]]> were apearing in search results if the content conatined jacvascript
                    indexItem.Content = SecurityHelper.RemoveMarkup(row["Body"].ToString());

                    indexItem.CreatedUtc = Convert.ToDateTime(row["CreatedDate"]);
                    indexItem.LastModUtc = Convert.ToDateTime(row["LastModUtc"]);

                    // lookup publish dates
                    foreach (PageModule pageModule in pageModules)
                    {
                        if (indexItem.ModuleId == pageModule.ModuleId)
                        {
                            indexItem.PublishBeginDate = pageModule.PublishBeginDate;
                            indexItem.PublishEndDate   = pageModule.PublishEndDate;
                        }
                    }

                    IndexHelper.RebuildIndex(indexItem, indexPath);

                    log.Debug("Indexed " + indexItem.Title);
                }
            }
            catch (System.Data.Common.DbException ex)
            {
                log.Error(ex);
            }
        }
예제 #6
0
        public override void DeleteSiteContent(int siteId)
        {
            HtmlRepository repository = new HtmlRepository();

            repository.DeleteBySite(siteId);
        }
예제 #7
0
        private void LoadSettings()
        {
            pageId   = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);

            //if (Request.Form.Count > 0)
            //{
            //    submittedContent = Server.UrlDecode(Request.Form.ToString()); // this gets the full content of the post

            //}

            if (Request.Form["html"] != null)
            {
                submittedContent = Request.Form["html"];
                //log.Info("html does = " + Request.Form["html"]);
            }


            //using (Stream s = Request.InputStream)
            //{
            //    using (StreamReader sr = new StreamReader(s))
            //    {
            //        string requestBody = sr.ReadToEnd();
            //        requestBody = Server.UrlDecode(requestBody);
            //        log.Info("requestBody was " + requestBody);
            //        JObject jObj = JObject.Parse(requestBody);
            //        submittedContent = (string)jObj["html"];
            //    }
            //}

            module = GetHtmlModule();

            if (module == null)
            {
                return;
            }

            currentUser    = SiteUtils.GetCurrentSiteUser();
            repository     = new HtmlRepository();
            moduleSettings = ModuleSettings.GetModuleSettings(module.ModuleId);
            config         = new HtmlConfiguration(moduleSettings);

            enableContentVersioning = config.EnableContentVersioning;

            if ((CurrentSite.ForceContentVersioning) || (WebConfigSettings.EnforceContentVersioningGlobally))
            {
                enableContentVersioning = true;
            }

            userCanOnlyEditAsDraft = UserCanOnlyEditModuleAsDraft(module.ModuleId, HtmlContent.FeatureGuid);

            if ((WebConfigSettings.EnableContentWorkflow) && (CurrentSite.EnableContentWorkflow))
            {
                workInProgress = ContentWorkflow.GetWorkInProgress(module.ModuleGuid);
            }

            if (workInProgress != null)
            {
                switch (workInProgress.Status)
                {
                case ContentWorkflowStatus.Draft:

                    //there is a draft version currently available, therefore dont allow the non draft version to be edited:

                    if (ViewMode == PageViewMode.WorkInProgress)
                    {
                        editDraft = true;
                    }

                    break;

                case ContentWorkflowStatus.ApprovalRejected:
                    //rejected content - allow update as draft only

                    if (ViewMode == PageViewMode.WorkInProgress)
                    {
                        editDraft = true;
                    }
                    break;

                case ContentWorkflowStatus.AwaitingApproval:
                    //pending approval - dont allow any edited:
                    // 2010-01-18 let editors update the draft if they want to before approving it.
                    editDraft = !userCanOnlyEditAsDraft;
                    break;
                }
            }


            //for (int i = 0; i < Request.QueryString.Count; i++)
            //{
            //    log.Info(Request.QueryString.GetKey(i) + " query param = " + Request.QueryString.Get(i));
            //}

            //if (Request.Form["c"] != null)
            //{
            //    submittedContent = Request.Form["c"];
            //    log.Info("c does = " + Request.Form["c"]);
            //}

            // this shows that a large html content post appears as multiple params
            //for (int i = 0; i < Request.Form.Count; i++)
            //{
            //    log.Info(Request.Form.GetKey(i) + " form param " + i.ToInvariantString() + " = " + Request.Form.Get(i));
            //}
        }
        public override void RebuildIndex(
            PageSettings pageSettings,
            string indexPath)
        {
            bool disableSearchIndex = ConfigHelper.GetBoolProperty("DisableSearchIndex", false);

            if (disableSearchIndex)
            {
                return;
            }

            if (pageSettings == null)
            {
                log.Error("pageSettings passed in to HtmlContentIndexBuilderProvider.RebuildIndex was null");
                return;
            }

            //don't index pending/unpublished pages
            if (pageSettings.IsPending)
            {
                return;
            }

            log.Info("HtmlContentIndexBuilderProvider indexing page - "
                     + pageSettings.PageName);

            try
            {
                Guid htmlFeatureGuid
                    = new Guid("113FB01C-6408-4607-B0F7-1379E2512396");
                ModuleDefinition htmlFeature
                    = new ModuleDefinition(htmlFeatureGuid);

                List <PageModule> pageModules
                    = PageModule.GetPageModulesByPage(pageSettings.PageId);

                HtmlRepository repository = new HtmlRepository();

                DataTable dataTable = repository.GetHtmlContentByPage(
                    pageSettings.SiteId,
                    pageSettings.PageId);

                foreach (DataRow row in dataTable.Rows)
                {
                    IndexItem indexItem = new IndexItem();
                    indexItem.SiteId   = pageSettings.SiteId;
                    indexItem.PageId   = pageSettings.PageId;
                    indexItem.PageName = pageSettings.PageName;

                    // generally we should not include the page meta because it can result in duplicate results
                    // one for each instance of html content on the page because they all use the smae page meta.
                    // since page meta should reflect the content of the page it is sufficient to just index the content
                    if ((ConfigurationManager.AppSettings["IndexPageMeta"] != null) && (ConfigurationManager.AppSettings["IndexPageMeta"] == "true"))
                    {
                        indexItem.PageMetaDescription = pageSettings.PageMetaDescription;
                        indexItem.PageMetaKeywords    = pageSettings.PageMetaKeyWords;
                    }

                    indexItem.ViewRoles       = pageSettings.AuthorizedRoles;
                    indexItem.ModuleViewRoles = row["ViewRoles"].ToString();
                    if (pageSettings.UseUrl)
                    {
                        indexItem.ViewPage             = pageSettings.Url.Replace("~/", string.Empty);
                        indexItem.UseQueryStringParams = false;
                    }
                    indexItem.FeatureId           = htmlFeatureGuid.ToString();
                    indexItem.FeatureName         = htmlFeature.FeatureName;
                    indexItem.FeatureResourceFile = htmlFeature.ResourceFile;

                    indexItem.ItemId      = Convert.ToInt32(row["ItemID"]);
                    indexItem.ModuleId    = Convert.ToInt32(row["ModuleID"]);
                    indexItem.ModuleTitle = row["ModuleTitle"].ToString();
                    indexItem.Title       = row["Title"].ToString();
                    // added the remove markup 2010-01-30 because some javascript strings like ]]> were apearing in search results if the content conatined jacvascript
                    indexItem.Content = SecurityHelper.RemoveMarkup(row["Body"].ToString());

                    // lookup publish dates
                    foreach (PageModule pageModule in pageModules)
                    {
                        if (indexItem.ModuleId == pageModule.ModuleId)
                        {
                            indexItem.PublishBeginDate = pageModule.PublishBeginDate;
                            indexItem.PublishEndDate   = pageModule.PublishEndDate;
                        }
                    }

                    IndexHelper.RebuildIndex(indexItem, indexPath);

                    log.Debug("Indexed " + indexItem.Title);
                }
            }
            catch (System.Data.Common.DbException ex)
            {
                log.Error(ex);
            }
        }
예제 #9
0
        private void LoadSettings()
        {
            ScriptConfig.IncludeColorBox = true;
            repository = new HtmlRepository();

            try
            {
                // this keeps the action from changing during ajax postback in folder based sites
                SiteUtils.SetFormAction(Page, Request.RawUrl);
            }
            catch (MissingMethodException)
            {
                //this method was introduced in .NET 3.5 SP1
            }

            virtualRoot = WebUtils.GetApplicationRoot();

            currentUser           = SiteUtils.GetCurrentSiteUser();
            timeOffset            = SiteUtils.GetUserTimeOffset();
            lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl();



            module = GetHtmlModule();

            if (module == null)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            if (module.ModuleTitle.Length == 0)
            {
                //this is not persisted just used for display if there is no title
                module.ModuleTitle = Resource.EditHtmlSettingsLabel;
            }


            heading.Text = Server.HtmlEncode(module.ModuleTitle);


            userCanEdit        = UserCanEdit(moduleId);
            userCanEditAsDraft = UserCanOnlyEditModuleAsDraft(moduleId, HtmlContent.FeatureGuid);

            divExcludeFromRecentContent.Visible = userCanEdit;

            pageSize = config.VersionPageSize;
            enableContentVersioning = config.EnableContentVersioning;

            if ((siteSettings.ForceContentVersioning) || (WebConfigSettings.EnforceContentVersioningGlobally))
            {
                enableContentVersioning = true;
            }

            if ((WebUser.IsAdminOrContentAdmin) || (SiteUtils.UserIsSiteEditor()))
            {
                isAdmin = true;
            }


            edContent.WebEditor.ToolBar = ToolBar.FullWithTemplates;


            if (moduleSettings.Contains("HtmlEditorHeightSetting"))
            {
                edContent.WebEditor.Height = Unit.Parse(moduleSettings["HtmlEditorHeightSetting"].ToString());
            }



            divHistoryDelete.Visible = (enableContentVersioning && isAdmin);

            pnlHistory.Visible = enableContentVersioning;



            SetupScript();


            html = repository.Fetch(moduleId);
            if (html == null)
            {
                html            = new HtmlContent();
                html.ModuleId   = moduleId;
                html.ModuleGuid = module.ModuleGuid;
            }

            if ((!userCanEdit) && (userCanEditAsDraft))
            {
                btnUpdate.Visible      = false;
                btnUpdateDraft.Visible = true;
            }

            btnUpdateDraft.Text = Resource.EditHtmlUpdateDraftButton;

            if ((WebConfigSettings.EnableContentWorkflow) && (siteSettings.EnableContentWorkflow))
            {
                workInProgress = ContentWorkflow.GetWorkInProgress(this.module.ModuleGuid);
                //bool draftOnlyAccess = UserCanOnlyEditModuleAsDraft(moduleId);

                if (workInProgress != null)
                {
                    // let editors toggle between draft and live view in the editor
                    if (userCanEdit)
                    {
                        SetupWorkflowControls(true);
                    }

                    switch (workInProgress.Status)
                    {
                    case ContentWorkflowStatus.Draft:

                        //there is a draft version currently available, therefore dont allow the non draft version to be edited:
                        btnUpdateDraft.Visible = true;
                        btnUpdate.Visible      = false;
                        if (ViewMode == PageViewMode.WorkInProgress)
                        {
                            //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusDraft;
                            heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.DraftFormat, module.ModuleTitle);
                            lblContentStatusLabel.SetOrAppendCss("wf-draft");     //JOE DAVIS
                            if (userCanEdit)
                            {
                                btnPublishDraft.Visible = true;
                            }
                        }



                        break;

                    case ContentWorkflowStatus.ApprovalRejected:
                        //rejected content - allow update as draft only
                        btnUpdateDraft.Visible = true;
                        btnUpdate.Visible      = false;
                        if (ViewMode == PageViewMode.WorkInProgress)
                        {
                            //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusRejected;
                            heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentRejectedFormat, module.ModuleTitle);
                            lblContentStatusLabel.SetOrAppendCss("wf-rejected");     //JOE DAVIS
                        }
                        break;

                    case ContentWorkflowStatus.AwaitingApproval:
                        //pending approval - dont allow any edited:
                        // 2010-01-18 let editors update the draft if they want to before approving it.
                        btnUpdateDraft.Visible = userCanEdit;

                        btnUpdate.Visible = false;
                        if (ViewMode == PageViewMode.WorkInProgress)
                        {
                            //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusAwaitingApproval;
                            heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentAwaitingApprovalFormat, module.ModuleTitle);
                            lblContentStatusLabel.SetOrAppendCss("wf-awaitingapproval");     //JOE DAVIS
                        }
                        break;

                    //JOE DAVIS
                    case ContentWorkflowStatus.AwaitingPublishing:
                        //pending publishing - allow editors, publishers, admin to update before publishing
                        btnUpdateDraft.Visible = userCanEdit;

                        btnUpdate.Visible = false;

                        if (ViewMode == PageViewMode.WorkInProgress)
                        {
                            heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentAwaitingPublishingFormat, module.ModuleTitle);
                            lblContentStatusLabel.SetOrAppendCss("wf-awaitingpublishing");
                        }
                        break;
                    }
                }
                else
                {
                    //workInProgress is null there is no draft
                    if (userCanEdit)
                    {
                        btnUpdateDraft.Text    = Resource.CreateDraftButton;
                        btnUpdateDraft.Visible = true;
                    }
                }

                if ((userCanEdit) && (ViewMode == PageViewMode.Live))
                {
                    btnUpdateDraft.Visible = false;
                    btnUpdate.Visible      = true;
                }
            }

            AddClassToBody("htmledit");
        }