/// <summary> /// write a LogItem in logItems table /// </summary> /// <param name="module">current module</param> /// <param name="description">the event log description</param> /// <param name="type">the event log type. default TracerItemType.Info</param> public static void Write(PigeonCms.Module module, string description, TracerItemType type) { if (module.UseLog == Utility.TristateBool.True || (module.UseLog == Utility.TristateBool.NotSet && LogProvider.AppUseLog)) { var item = new LogItem(); var man = new LogItemsManager(); item.ModuleId = module.Id; item.Type = type; try { //sometimes throw NullReferenceException item.UserHostAddress = HttpContext.Current.Request.UserHostAddress; } catch { } try { //sometimes throw NullReferenceException item.SessionId = HttpContext.Current.Session.SessionID; } catch { } //item.Url = HttpContext.Current.Request.RawUrl; //parte finale item.Url = Utility.Html.GetTextPreview(HttpContext.Current.Request.Url.AbsoluteUri, 495, ""); //all url item.Description = Utility.Html.GetTextPreview(description, 495, ""); man.Insert(item); } }
public const string ContentTemplateBlock = "content"; //name of content template block (mainbody of the page) #endregion Fields #region Methods /// <summary> /// load the modules for the selected menu entry /// </summary> /// <param name="menuAlias">pgn_menu.alias</param> public static void LoadModules(PigeonCms.Menu menuEntry, Page currPage) { Tracer.Log("LoadModules(menu:" + menuEntry.ToString() + ", currPage:" + currPage + ")", TracerItemType.Debug); if (menuEntry.Published && !string.IsNullOrEmpty(menuEntry.Name)) { if (menuEntry.OverridePageTitle) { var myMaster = (BaseMasterPage)currPage.Master; myMaster.PageTitle = menuEntry.TitleWindow; } //loop through templateBlocks in current masterpage foreach (Control cpl in currPage.Master.FindControl("Form1").Controls) { if (cpl is ContentPlaceHolder) { string cplName = cpl.ID.Substring(3).ToLower(); //CphPlaceholdername --> Placeholdername if (cplName != ContentTemplateBlock) { //check and load which modules fill in current templateBlock foreach (var currModule in menuEntry.ModulesList) { if (currModule.TemplateBlockName.ToLower() == cplName) renderModule(currPage, cpl, currModule, menuEntry); } } else { //load page content module renderModule(currPage, cpl, menuEntry.ContentModule, menuEntry); } } } } }
public static void Log(PigeonCms.Module module, string message, params object[] arguments) { //inject module info message = "module(" + module.Id.ToString() + "|" + module.ModuleFullName + "|" + module.Title + "):" + message; Log(message, TracerItemType.Info, arguments); }
/// <summary> /// write a LogItem in logItems table. default TracerItemType.Info /// </summary> public static void Write(PigeonCms.Module module, string description) { Write(module, description, TracerItemType.Info); }
public static void InitEditor(PigeonCms.BaseModuleControl control, UpdatePanel upd1, Configuration config) { string extra = ""; string editorTheme = ""; string contentCss = ""; string editorCss = ""; //control.ResolveUrl("~/Css/common.css"); string initEditorText = ""; var cssList = new DirectoryInfo( HttpContext.Current.Server.MapPath("~/App_Themes/" + PigeonCms.Config.CurrentTheme)).GetFiles("*.css"); foreach (var file in cssList) { editorCss += control.ResolveUrl( "~/App_Themes/" + PigeonCms.Config.CurrentTheme + "/" + file.Name) + ","; } if (editorCss.EndsWith(",")) editorCss = editorCss.Substring(0, editorCss.Length - 1); if (!string.IsNullOrEmpty(editorCss)) contentCss = "content_css: '" + editorCss + @"', "; switch (config.EditorType) { case Configuration.EditorTypeEnum.Html: editorTheme = "advanced"; break; case Configuration.EditorTypeEnum.BasicHtml: editorTheme = "simple"; //extra = "paste_text_sticky : true, paste_text_sticky_default : true,"; /*extra = @" setup: function(ed) { // Force Paste-as-Plain-Text ed.onPaste.add( function(ed, e, o) { ed.execCommand(‘mcePasteText’, true); return tinymce.dom.Event.cancel(e); }); }, ";*/ break; case Configuration.EditorTypeEnum.Text: default: editorTheme = ""; break; } if (config.EditorType == Configuration.EditorTypeEnum.Text || config.EditorType == Configuration.EditorTypeEnum.Image) { initEditorText = "function initEditor() {}"; } else { initEditorText = @" var stylesheets = [];//not used $('link[rel=stylesheet]').each(function() { stylesheets += $(this).attr('href') + ','; }); function initEditor() { tinymce.remove('textarea'); tinymce.init({ selector: 'textarea', relative_urls: false, plugins: [ 'advlist autolink link image lists charmap print preview hr anchor pagebreak ', 'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking', 'save table contextmenu directionality emoticons template paste textcolor' ],/*plugins-removed: spellchecker*/ image_advtab: true, content_css: '" + editorCss + @"', extended_valid_elements: 'iframe[class|src|frameborder=0|alt|title|width|height|align|name]'/*picce 20150811*/ }); } "; //per version 3.x /*tinyMCE.init({ mode: 'textareas', theme: '" + editorTheme + @"', relative_urls: false, "+ contentCss + @" "+ extra + @" plugins: 'safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template', theme_advanced_buttons1: 'bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect', theme_advanced_buttons2: 'search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code', theme_advanced_buttons3: 'hr,removeformat,visualaid,|,sub,sup,|,charmap,|,fullscreen,|,template', theme_advanced_toolbar_location: 'top', theme_advanced_toolbar_align: 'left', theme_advanced_statusbar_location: 'bottom', theme_advanced_resizing: true, extended_valid_elements: 'iframe[class|src|frameborder=0|alt|title|width|height|align|name]' });*/ } //tinyMce editor Utility.Script.RegisterClientScriptInclude(control, "tinymce", control.ResolveUrl(Config.VendorPath + "tiny_mce/tinymce.min.js")); Utility.Script.RegisterClientScriptBlock(control, "initEditorText", initEditorText); Utility.Script.RegisterClientScriptBlock(control, "insertEditorText", @" function insertEditorText(text) { tinyMCE.execCommand('mceInsertContent',false,text); } "); Utility.Script.RegisterClientScriptBlock(control, "insertReadmore()", @" function insertReadmore() { var content = tinyMCE.activeEditor.getContent(); if (content.match(/<hr\s+class=(""|')system-readmore(""|')\s*\/*>/i)) { //alert('There is already a Read more... link that has been inserted. Only one such link is permitted. Use {pagebreak} to split the page up further.'); return false; } else { insertEditorText('"+ ContentEditorProvider.SystemReadMoreTag + @"'); } } "); Utility.Script.RegisterClientScriptBlock(control, "insertPagebreak()", @" function insertPagebreak() { var content = tinyMCE.activeEditor.getContent(); insertEditorText('"+ ContentEditorProvider.SystemPagebreakTag + @"'); } "); //use title->titolo e alt->alias Utility.Script.RegisterClientScriptBlock(control, "insertFile()", @" function insertFile() { $('<a href="""+ config.FilesUploadUrl + @"""></a>').fancybox({ 'width': '80%', 'height': '80%', 'type': 'iframe', 'hideOnContentClick': false, onClosed: function () { } }).click(); } "); Utility.Script.RegisterClientScriptBlock(control, "toggleEditor()", @" function toggleEditor() { //tinyMCE.execCommand('mceToggleEditor',false,'<client.id here>'); //tinyMCE.activeEditor.hide(); } "); Utility.Script.RegisterStartupScript(upd1, "initEditor", @" try{ if (typeof(initEditor) != 'undefined') { setTimeout(function() { initEditor(); }, 200); } } catch(err) {} "); control.Page.ClientScript.RegisterOnSubmitStatement(control.GetType(), "save", "tinyMCE.triggerSave();"); }
private void values2obj(PigeonCms.AttributeValue obj) { var valueTranslation = new Dictionary<string, string>(); if (ChkInLang.Checked) { foreach (KeyValuePair<string, string> item in Config.CultureList) { TextBox t1 = new TextBox(); t1 = (TextBox)PanelTitle.FindControl("TxtTitle" + item.Value); valueTranslation.Add(item.Key, t1.Text); } } else { TextBox t1 = new TextBox(); string defaultLang = Config.CultureList.FirstOrDefault(x => x.Key == Config.CultureDefault).Value; t1 = (TextBox)PanelTitle.FindControl("TxtTitle" + defaultLang); foreach (KeyValuePair<string, string> item in Config.CultureList) { valueTranslation.Add(item.Key, t1.Text); } } obj.ValueString = toJson(valueTranslation); if (base.CurrentId == 0) { // have to save attribute before var a = new PigeonCms.Attribute(); a.AllowCustomValue = ChkCustomValue.Checked; a.Name = TxtName.Text; a = new AttributesManager().Insert(a); base.CurrentId = a.Id; } obj.AttributeId = base.CurrentId; }
private void values2form(PigeonCms.AttributeValue obj) { foreach (KeyValuePair<string, string> item in Config.CultureList) { string sTitleTranslation = ""; TextBox t1 = new TextBox(); t1 = (TextBox)PanelTitle.FindControl("TxtTitle" + item.Value); obj.ValueTranslations.TryGetValue(item.Key, out sTitleTranslation); if (string.IsNullOrEmpty(sTitleTranslation)) obj.ValueTranslations.TryGetValue(Config.CultureDefault, out sTitleTranslation); t1.Text = sTitleTranslation; } }
private void obj2form(PigeonCms.Attribute obj) { TxtName.Text = obj.Name; ChkCustomValue.Checked = obj.AllowCustomValue; // disable insert and edit if we have custom value, but allow to view values inserted. if (obj.AllowCustomValue) { foreach (KeyValuePair<string, string> item in Config.CultureList) { TextBox t1 = (TextBox)PanelTitle.FindControl("TxtTitle" + item.Value); t1.Enabled = false; } BtnAddValue.Enabled = false; BtnNewValue.Enabled = false; } }
private void form2obj(PigeonCms.Attribute obj) { obj.Id = base.CurrentId; obj.AllowCustomValue = ChkCustomValue.Checked; obj.Name = TxtName.Text; }
private void obj2form(PigeonCms.ModuleType obj) { LblModuleId.Text = obj.FullName; }
private void form2obj(PigeonCms.Menu obj) { obj.Id = base.CurrentId; //obj.MenuType = DropMenuTypes.SelectedValue; }
private void obj2form(PigeonCms.Menu obj, bool changeType, bool changeView) { foreach (KeyValuePair<string, string> item in Config.CultureList) { string sTitleTranslation = ""; TextBox t1 = new TextBox(); t1 = (TextBox)PanelTitle.FindControl("TxtTitle" + item.Value); obj.TitleTranslations.TryGetValue(item.Key, out sTitleTranslation); t1.Text = sTitleTranslation; string sTitleWindowTranslation = ""; TextBox t2 = new TextBox(); t2 = (TextBox)PanelTitleWindow.FindControl("TxtTitleWindow" + item.Value); obj.TitleWindowTranslations.TryGetValue(item.Key, out sTitleWindowTranslation); t2.Text = sTitleWindowTranslation; } LblId.Text = obj.Id.ToString(); LblModuleId.Text = obj.ModuleId.ToString(); //Utility.SetDropByValue(DropMenuTypes, obj.MenuType); not used, list filtered on MenuType yet Utility.SetDropByValue(DropReferMenuId, obj.ReferMenuId.ToString()); ChkVisible.Checked = obj.Visible; ChkPublished.Checked = obj.Published; ChkOverridePageTitle.Checked = obj.OverridePageTitle; LitMenuType.Text = DropMenuTypesFilter.SelectedValue; ChkIsCore.Checked = obj.IsCore; PermissionsControl1.Obj2form(obj); Module currModule = new Module(); if (obj.ContentType == MenuContentType.Module) { if (obj.ModuleId == 0 && obj.Id == 0) { if (changeType) { currModule.ModuleNamespace = DropModuleTypes.SelectedValue.Split('.')[0]; currModule.ModuleName = DropModuleTypes.SelectedValue.Split('.')[1]; } else { currModule.ModuleNamespace = DropNewItem.SelectedValue.Split('.')[0]; currModule.ModuleName = DropNewItem.SelectedValue.Split('.')[1]; } } else { string moduleFullName = ""; moduleFullName = new ModulesManager().GetByKey(obj.ModuleId).ModuleFullName; if (!new ModuleTypeManager().Exist(moduleFullName)) { LitErr.Text = RenderError( Utility.GetErrorLabel("NotInstalledModuleType", "Not installed module type")); //LitModuleType.Text += " " + Utility.GetErrorLabel("NotInstalledModuleType", "Not installed module type"); } currModule = new ModulesManager().GetByKey(obj.ModuleId); if (changeType) { currModule.ModuleNamespace = DropModuleTypes.SelectedValue.Split('.')[0]; currModule.ModuleName = DropModuleTypes.SelectedValue.Split('.')[1]; } else Utility.SetDropByValue(DropModuleTypes, moduleFullName); } if (changeView) currModule.CurrView = DropViews.SelectedValue; else { loadDropViews(currModule); Utility.SetDropByValue(DropViews, currModule.CurrView); } ChkShowModuleTitle.Checked = currModule.ShowTitle; ModuleParams1.LoadParams(currModule); } else { Utility.SetDropByValue(DropModuleTypes, ((int)obj.ContentType).ToString()); //LitModuleType.Text = obj.ContentType.ToString(); ModuleParams1.LoadParams(currModule); //to reset params panel } Utility.SetDropByValue(DropCurrMasterPage, obj.CurrMasterPageStored); Utility.SetDropByValue(DropCurrTheme, obj.CurrThemeStored); Utility.SetDropByValue(DropRouteId, obj.RouteId.ToString()); Utility.SetDropByValue(DropUseSsl, ((int)obj.UseSsl).ToString()); TxtName.Text = obj.Name; TxtAlias.Text = obj.Alias; TxtLink.Text = obj.Link; TxtCssClass.Text = obj.CssClass; //load parentId list MenuHelper.LoadListMenu(ListParentId, DropMenuTypesFilter.SelectedValue, base.CurrentId); if (obj.ParentId > 0) Utility.SetListBoxByValues(ListParentId, obj.ParentId); else Utility.SetListBoxByValues(ListParentId, obj.MenuType); //MenuContentType specific switch (obj.ContentType) { case MenuContentType.Module: lockControl(TxtLink, false); lockControl(DropReferMenuId, false); break; case MenuContentType.Url: lockControl(TxtAlias, false); ReqAlias.Enabled = false; lockControl(DropReferMenuId, false); lockControl(DropViews, false); break; case MenuContentType.Javascript: lockControl(TxtAlias, false); ReqAlias.Enabled = false; lockControl(DropReferMenuId, false); lockControl(DropViews, false); break; case MenuContentType.Alias: lockControl(TxtLink, false); lockControl(DropViews, false); break; default: break; } if (obj.IsCore) lnkchange.Visible = false; else lnkchange.Visible = true; }
private void form2obj(PigeonCms.Menu obj) { obj.Id = base.CurrentId; obj.MenuType = LitMenuType.Text; obj.Visible = ChkVisible.Checked; obj.Published = ChkPublished.Checked; obj.OverridePageTitle = ChkOverridePageTitle.Checked; obj.Name = TxtName.Text; obj.Alias = TxtAlias.Text; obj.Link = TxtLink.Text; obj.CssClass = TxtCssClass.Text; obj.CurrMasterPageStored = DropCurrMasterPage.SelectedValue; obj.CurrThemeStored = DropCurrTheme.SelectedValue; obj.IsCore = ChkIsCore.Checked; obj.UseSsl = (Utility.TristateBool)int.Parse(DropUseSsl.SelectedValue); PermissionsControl1.Form2obj(obj); //route obj.RouteId = 1; if (!string.IsNullOrEmpty(DropRouteId.SelectedValue)) { obj.RouteId = int.Parse(DropRouteId.SelectedValue); } obj.TitleTranslations.Clear(); obj.TitleWindowTranslations.Clear(); foreach (KeyValuePair<string, string> item in Config.CultureList) { TextBox t1 = new TextBox(); t1 = (TextBox)PanelTitle.FindControl("TxtTitle" + item.Value); obj.TitleTranslations.Add(item.Key, t1.Text); TextBox t2 = new TextBox(); t2 = (TextBox)PanelTitleWindow.FindControl("TxtTitleWindow" + item.Value); obj.TitleWindowTranslations.Add(item.Key, t2.Text); } int newItemValue = -1; if (int.TryParse(DropModuleTypes.SelectedValue, out newItemValue)) { obj.ContentType = (MenuContentType)newItemValue; } else { obj.ContentType = MenuContentType.Module; } if (base.CurrentId == 0) { } if (obj.ContentType == MenuContentType.Alias) { int referMenuId = 0; if (int.TryParse(DropReferMenuId.SelectedValue, out referMenuId)) { obj.ReferMenuId = referMenuId; } } int parentId = 0; foreach (ListItem item in ListParentId.Items) { if (item.Selected) { if (int.TryParse(item.Value, out parentId)) obj.ParentId = parentId; } } obj.ParentId = parentId; }
private bool form2module(PigeonCms.Menu menu, Module currModule) { bool res = true; int dropValue = -1; if (int.TryParse(DropModuleTypes.SelectedValue, out dropValue)) { res = false; } else { currModule.ModuleNamespace = DropModuleTypes.SelectedItem.Text.Split('.')[0]; currModule.ModuleName = DropModuleTypes.SelectedItem.Text.Split('.')[1]; currModule.ModuleParams = FormBuilder.GetParamsString(currModule.ModuleType.Params, ModuleParams1); if (!string.IsNullOrEmpty(currModule.CurrView)) { //loads current view specific params PigeonCms.ModuleType viewType = null; viewType = new ModuleTypeManager().GetByFullName( currModule.ModuleFullName, currModule.CurrView.Replace(".ascx", ".xml")); if (viewType != null) currModule.ModuleParams += "|" + FormBuilder.GetParamsString(viewType.Params, ModuleParams1); } currModule.TitleTranslations = menu.TitleTranslations; currModule.ShowTitle = ChkShowModuleTitle.Checked; currModule.TemplateBlockName = ModuleHelper.ContentTemplateBlock; currModule.MenuSelection = ModulesMenuSelection.MenuContent; currModule.CurrView = DropViews.SelectedValue; currModule.CssFile = ModuleParams1.CssFile; currModule.CssClass = ModuleParams1.CssClass; currModule.UseCache = ModuleParams1.UseCache; currModule.UseLog = ModuleParams1.UseLog; currModule.DirectEditMode = ModuleParams1.DirectEditMode; currModule.SystemMessagesTo = ModuleParams1.SystemMessagesTo; } return res; }
/// <summary> /// render currModule ascx control in currPage>cpl /// </summary> /// <param name="currPage">current page</param> /// <param name="cpl">current placeholder</param> /// <param name="currModule">module (ascx control) to load dynamically</param> private static void renderModule(Page currPage, Control cpl, PigeonCms.Module currModule, PigeonCms.Menu currMenu) { string modulePath; Tracer.Log("renderModule(module:" + currModule.ToString() + ")", TracerItemType.Debug); try { modulePath = Config.ModulesPath + currModule.ModuleFullName + "/views/" + currModule.CurrView; if (!new FileInfo(HttpContext.Current.Request.MapPath(modulePath)).Exists) { modulePath = Config.ModulesPath + currModule.ModuleFullName + "/views/" + currModule.ModuleName + ".ascx"; } if (!new FileInfo(HttpContext.Current.Request.MapPath(modulePath)).Exists) { throw new CustomException("Missing module rendering file: " + modulePath, CustomExceptionSeverity.Warning, CustomExceptionLogLevel.Debug); } HtmlGenericControl moduleTag = new HtmlGenericControl("div"); //module container HtmlGenericControl moduleTitleTag = new HtmlGenericControl(); //module title container HtmlGenericControl moduleContentTag = new HtmlGenericControl("div"); //module content container Control ctrl1 = currPage.LoadControl(modulePath); Type typeUserControl = ctrl1.GetType(); //set Param BaseModule PropertyInfo propBaseModule = null; propBaseModule = typeUserControl.GetProperty("BaseModule"); propBaseModule.SetValue(ctrl1, currModule, null); //set param CurrMenu PropertyInfo propCurrMenu = null; propCurrMenu = typeUserControl.GetProperty("CurrMenu"); propCurrMenu.SetValue(ctrl1, currMenu, null); moduleTitleTag.TagName = "div"; moduleTitleTag.Attributes["class"] = "title"; if (currModule.ShowTitle) { moduleTitleTag.InnerHtml = currModule.Title; } //direct content edit TO COMPLETE if (PgnUserCurrent.IsAuthenticated && Roles.IsUserInRole("admin") && !string.IsNullOrEmpty(currModule.EditContentUrl)/*WARN:cause GetList() */) { string titleString = "edit " + currModule.Title + " [" + currModule.ModuleFullName + "]"; string src = Utility.GetThemedImageSrc("EditFile.gif", "adminDefault"); moduleTitleTag.InnerHtml += "<a class='fancy editContent' href='" + currModule.EditContentUrl + "'>" + "<img src='" + src + "' title='" + titleString + "' />" + "</a>"; } moduleTag.Attributes["class"] = "module"; moduleContentTag.Attributes["class"] = "moduleContent"; if (!string.IsNullOrEmpty(currModule.CssClass)) moduleTag.Attributes["class"] += " " + currModule.CssClass; moduleTag.Controls.Add(moduleTitleTag); moduleTag.Controls.Add(moduleContentTag); moduleContentTag.Controls.Add(ctrl1); if (HttpContext.Current.Request.QueryString["tp"] == "1" && PgnUserCurrent.IsAuthenticated && Roles.IsUserInRole("debug")) { //modules structure only for users in debug role HtmlGenericControl divPreview = new HtmlGenericControl("div"); divPreview.Attributes["class"] = "mod-preview"; HtmlGenericControl divPreviewInfo = new HtmlGenericControl("div"); divPreviewInfo.Attributes["class"] = "mod-preview-info"; divPreviewInfo.InnerHtml = currModule.TemplateBlockName + " - " + currModule.Title + "<br />[" + currModule.ModuleFullName + "]"; HtmlGenericControl divPreviewWrapper = new HtmlGenericControl("div"); divPreviewWrapper.Attributes["class"] = "mod-preview-wrapper"; divPreviewWrapper.Controls.Add(moduleTag); divPreview.Controls.Add(divPreviewInfo); divPreview.Controls.Add(divPreviewWrapper); ContentPlaceHolder ct = (ContentPlaceHolder)cpl; ct.Controls.Add(divPreview); } else { ContentPlaceHolder ct = (ContentPlaceHolder)cpl; ct.Controls.Add(moduleTag); } } catch (Exception e) { PigeonCms.Tracer.Log("Error loading control " + currModule.ModuleFullName + ": " + e.ToString(), TracerItemType.Error); } }