/// <summary> /// External modules (found in external DLL assembies) can provide a class that inherits from CmsModuleInfo to provide information on /// the module. /// </summary> /// <returns></returns> public static CmsModuleInfo[] getAllModuleInfos() { string cacheKey = "CmsModuleUtils.getAllModuleInfos()"; if (PerRequestCache.CacheContains(cacheKey)) { return((CmsModuleInfo[])PerRequestCache.GetFromCache(cacheKey, new CmsModuleInfo[0])); } List <CmsModuleInfo> ret = new List <CmsModuleInfo>(); Type[] moduleInfoTypes = AssemblyHelpers.LoadAllAssembliesAndGetAllSubclassesOf(typeof(CmsModuleInfo)); foreach (Type modInfoType in moduleInfoTypes) { try { CmsModuleInfo info = (CmsModuleInfo)modInfoType.Assembly.CreateInstance(modInfoType.FullName); ret.Add(info); } catch { Console.Write("Error: could not load module info " + modInfoType.FullName); } } // foreach CmsModuleInfo[] arr = ret.ToArray(); PerRequestCache.AddToCache(cacheKey, arr); return(arr); }
public static BaseCmsAdminTool[] GetAllCachedAdminToolInstances() { string cacheKey = "GetAllCachedAdminToolInstances"; if (PerRequestCache.CacheContains(cacheKey)) { return((BaseCmsAdminTool[])PerRequestCache.GetFromCache(cacheKey, new BaseCmsAdminTool[0])); } Type[] allAdminTypes = Hatfield.Web.Portal.AssemblyHelpers.LoadAllAssembliesAndGetAllSubclassesOf(typeof(BaseCmsAdminTool)); List <BaseCmsAdminTool> ret = new List <BaseCmsAdminTool>(); foreach (Type t in allAdminTypes) { BaseCmsAdminTool tool = (BaseCmsAdminTool)t.Assembly.CreateInstance(t.FullName); if (tool != null) { ret.Add(tool); } } PerRequestCache.AddToCache(cacheKey, ret.ToArray()); return(ret.ToArray()); }
/// <summary> /// Caches all BaseCmsControl types on a per-request basis. This makes the fetching of control types much faster. /// </summary> /// <returns></returns> public static Type[] GetAllCachedBaseCmsControlDerivedClasses() { string cacheKey = "GetAllCachedBaseCmsControlDerivedClasses"; if (PerRequestCache.CacheContains(cacheKey)) { return((Type[])PerRequestCache.GetFromCache(cacheKey, new Type[0])); } Type[] ret = AssemblyHelpers.LoadAllAssembliesAndGetAllSubclassesOf(typeof(HatCMS.Controls.BaseCmsControl)); PerRequestCache.AddToCache(cacheKey, ret); return(ret); }
/// <summary> /// gets a CmsPage from the database with the given path in the currentLanguage. /// The pagePath should NEVER includes the language shortCode. /// Returns an empty CmsPage (with id = -1) if the page was not found. /// </summary> /// <param name="pagePath"></param> /// <returns>the CmsPage with the given path. If not found, an empty CmsPage (with id = -1) is returned</returns> public static CmsPage getPageByPath(string pagePath) { string cacheKey = "page" + pagePath.Trim().ToLower(); if (PerRequestCache.CacheContains(cacheKey)) { return((CmsPage)PerRequestCache.GetFromCache(cacheKey, new CmsPage())); } CmsPage ret = CmsPage.FetchPageByPath(pagePath); PerRequestCache.AddToCache(cacheKey, ret); return(ret); }
public static CmsPortalApplication GetInstance() { string key = (new CmsPortalApplication()).GetApplicationName(); if (PerRequestCache.CacheContains(key)) { return((CmsPortalApplication)PerRequestCache.GetFromCache(key, null)); } else { CmsPortalApplication p = new CmsPortalApplication(); PerRequestCache.AddToCache(key, p); p.EnsurePermissionsInDatabase(); return(p); } }
/// <summary> /// Gets the current <see cref="PageCache"/>instance. Note: for internal use only. /// </summary> /// <returns></returns> public static CmsPageCache getPageCache() { string cacheKey = "hatCmsPageCache"; if (PerRequestCache.CacheContains(cacheKey)) { return((CmsPageCache)PerRequestCache.GetFromCache(cacheKey, new CmsPageCache())); } else { if (_pageCacheObject == null) { _pageCacheObject = new CmsPageCache(); } PerRequestCache.AddToCache(cacheKey, _pageCacheObject); return(_pageCacheObject); } }
/// <summary> /// To define a filter in a class, create a function CmsOutputFilter[] getOutputFilters(){}; /// Gets all Output Filters from all objects defined in this assembly. The result is cached on a per-request basis. /// </summary> /// <returns></returns> private static Dictionary <CmsOutputFilterScope, CmsOutputFilterInfo[]> GetAllOutputFilterInfos() { string cacheKey = "GetAllOutputFilterInfos"; if (PerRequestCache.CacheContains(cacheKey)) { return((Dictionary <CmsOutputFilterScope, CmsOutputFilterInfo[]>)PerRequestCache.GetFromCache(cacheKey, new Dictionary <CmsOutputFilterScope, CmsOutputFilterInfo[]>())); } System.Type[] filterTypes = Hatfield.Web.Portal.AssemblyHelpers.LoadAllAssembliesAndGetAllSubclassesOf(typeof(BaseCmsOutputFilter)); List <CmsOutputFilterInfo> allFilters = new List <CmsOutputFilterInfo>(); try { foreach (Type type in filterTypes) { try { BaseCmsOutputFilter filter = (BaseCmsOutputFilter)type.Assembly.CreateInstance(type.FullName); CmsOutputFilterInfo info = filter.getOutputFilterInfo(); allFilters.Add(info); } catch (Exception ex) { Console.Write(ex.Message); } } // foreach type } catch (Exception ex) { Console.Write(ex.Message); } Dictionary <CmsOutputFilterScope, CmsOutputFilterInfo[]> ret = toDictionary(allFilters); PerRequestCache.AddToCache(cacheKey, ret); return(ret); } // GetAlloutputFilters
public override string RenderToString(CmsControlDefinition controlDefnToRender, CmsLanguage langToRenderFor) { // -- don't render anything unless the user is logged in. if (!CmsContext.currentUserIsLoggedIn) { return(""); } StringBuilder html = new StringBuilder(); CmsPage page = CmsContext.currentPage; if (!page.currentUserCanWrite) // if the page is not writable, skip rendering the edit menu { return(""); } // -- use the PerRequest cache to ensure that this control is only displayed once (not multiple times per language) string cacheName = "FloatingEditMenu"; if (PerRequestCache.CacheContains(cacheName)) { throw new TemplateExecutionException(page.TemplateName, "The FloatingEditMenu control should be placed after the ##EndPageBody## template file statement."); } PerRequestCache.AddToCache(cacheName, true); page.HeadSection.AddEmbeddedJavascriptFile(JavascriptGroup.ControlOrPlaceholder, typeof(FloatingEditMenu).Assembly, "FloatingEditMenu.js"); string divId = "editConsole_" + page.Id.ToString(); string persistKey = "editConsole_" + page.TemplateName + CmsContext.currentEditMode.ToString(); persistKey = persistKey.Replace("/", "_"); persistKey = persistKey.Replace("\\", "_"); persistKey = persistKey.Replace(" ", "_"); string consoleDivId = "editConsoleOptions_" + page.Id.ToString(); string leftPos = "580px"; string topPos = "30px"; // -- read the position of the floating toolbar from the cookie. // note that the cookie name must be the same as is defined in FloatingEditMenu.js. if (HttpContext.Current != null && HttpContext.Current.Request != null) { System.Web.HttpRequest req = HttpContext.Current.Request; if (req.Cookies[persistKey + "_left"] != null && req.Cookies[persistKey + "_top"] != null) { string l = req.Cookies[persistKey + "_left"].Value; string t = req.Cookies[persistKey + "_top"].Value; if (l.EndsWith("px") && t.EndsWith("px")) { try { // if the edit menu is off the screen, move it back into view. // note: for max screen sizes, you can not use Request.Browser.ScreenPixelsWidth int ll = Convert.ToInt32(l.Substring(0, l.Length - "px".Length)); int tt = Convert.ToInt32(t.Substring(0, t.Length - "px".Length)); if (ll < 10) { ll = 10; } if (tt < 10) { tt = 10; } leftPos = ll.ToString() + "px"; topPos = tt.ToString() + "px"; } catch { } } } } html.Append("<div id=\"" + divId + "\" ondblclick=\"OpenCloseDiv('" + consoleDivId + "')\" style=\"PADDING-RIGHT: 0px; PADDING-LEFT: 0px; Z-INDEX: 10; PADDING-BOTTOM: 0px; WIDTH: 200px; PADDING-TOP: 0px; POSITION: absolute; LEFT: " + leftPos + "; TOP: " + topPos + "; BACKGROUND-COLOR: transparent; TEXT-ALIGN: left\">"); html.Append("<table class=\"wbcedit\" onmouseover=\"drag('" + divId + "','" + persistKey + "')\" onfocus=\"this.blur()\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">"); html.Append("<tr>"); html.Append("<td ondblclick=\"OpenCloseDiv('" + consoleDivId + "')\" style=\"cursor: move; font-family: arial; padding-left: 5px; padding-right: 5px; background-color: #4a87bd; opacity:0.95; filter:alpha(opacity=95); text-align: center;\">"); html.Append("<span style=\"font-weight: bold;\">Edit Menu</span><span style=\"font-size: 8pt;\"><br /><nobr>(drag here to move menu)</span></nobr></td>"); html.Append("<td style=\"background-color: #4a87bd; opacity:0.95; filter:alpha(opacity=95);\"><img src=\"" + CmsContext.ApplicationPath + "images/_system/hatCms_logo.png\" /></td>"); html.Append("</tr>"); html.Append("</table>"); html.Append("<div class=\"wbcedit\" id=\"" + consoleDivId + "\">"); html.Append("<table borderColor=\"#4a87bd\" cellSpacing=\"0\" cellPadding=\"5\" width=\"100%\" border=\"3\" style=\"border-top-right-radius: 4px; -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; border-bottom-right-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px;\">"); html.Append(" <tr>"); html.Append("<td nowrap=\"nowrap\" style=\"background: yellow; opacity:0.95; filter:alpha(opacity=95); font-size: 10pt; font-family: arial;\" >"); html.Append(getCurrentEditMenuActionsHtml(page)); html.Append("</td>"); html.Append("</tr>"); html.Append("</table>"); html.Append("</div>"); html.Append("</div>"); return(html.ToString()); }