PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Web/Services/TinyMceTemplates.ashx.cs

#
C# | 193 lines | 135 code | 41 blank | 17 comment | 29 complexity | 3f1f0eb523c420b3821e1bacd5be762e MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause, CPL-1.0, CC-BY-SA-3.0, GPL-2.0
  1. // Author: Joe Audette
  2. // Created: 2009-08-14
  3. // Last Modified: 2011-04-08
  4. //
  5. // Licensed under the terms of the GNU Lesser General Public License:
  6. // http://www.opensource.org/licenses/lgpl-license.php
  7. //
  8. // You must not remove this notice, or any other, from this software.
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Globalization;
  12. using System.Data;
  13. using System.IO;
  14. using System.Web;
  15. using System.Collections;
  16. using System.Text;
  17. using System.Web.Services;
  18. using System.Web.Services.Protocols;
  19. using System.Xml;
  20. using mojoPortal.Business;
  21. using mojoPortal.Business.WebHelpers;
  22. using mojoPortal.Web.Framework;
  23. using Resources;
  24. namespace mojoPortal.Web.Services
  25. {
  26. /// <summary>
  27. /// When a template guid is passed returns html contentof the template,
  28. /// otherwise returns a json list of templates
  29. /// http://wiki.moxiecode.com/index.php/TinyMCE:Index
  30. /// http://wiki.moxiecode.com/index.php/TinyMCE:Custom_filebrowser
  31. /// http://wiki.moxiecode.com/index.php/TinyMCE:Configuration
  32. /// http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template
  33. /// http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/theme_advanced_blockformats
  34. /// </summary>
  35. [WebService(Namespace = "http://tempuri.org/")]
  36. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  37. public class TinyMceTemplates : IHttpHandler
  38. {
  39. private SiteSettings siteSettings = null;
  40. private Guid templateGuid = Guid.Empty;
  41. private string templateGuidString = string.Empty;
  42. private string siteRoot = string.Empty;
  43. private string comma = string.Empty;
  44. private const string jQueryAccordionGuid = "e110400d-c92d-4d78-a830-236f584af115";
  45. private const string jQueryAccordionNoHeightGuid = "08e2a92f-d346-416b-b37b-bd82acf51514";
  46. private const string jQueryTabsGuid = "7efaeb03-a1f9-4b08-9ffd-46237ba993b0";
  47. private const string YuiTabsGuid = "046dae46-5301-45a5-bcbf-0b87c2d9e919";
  48. private const string faqGuid = "ad5f5b63-d07a-4e6b-bbd5-2b6201743dab";
  49. private const string Columns2Over1Guid = "cfb9e9c4-b740-42f5-8c16-1957b536b8e9";
  50. private const string Columns3Over1Guid = "9ac79a8d-7dfd-4485-af3c-b8fdf256bbb8";
  51. private const string Columns4Over1Guid = "28ae8c68-b619-4e23-8dde-17d0a34ee7c6";
  52. public void ProcessRequest(HttpContext context)
  53. {
  54. siteSettings = CacheHelper.GetCurrentSiteSettings();
  55. if (siteSettings == null)
  56. {
  57. return;
  58. }
  59. templateGuid = WebUtils.ParseGuidFromQueryString("g", templateGuid);
  60. if (templateGuid != Guid.Empty) { templateGuidString = templateGuid.ToString(); }
  61. if (templateGuid != Guid.Empty)
  62. {
  63. RenderTemplate(context);
  64. }
  65. else
  66. {
  67. RenderJsonList(context);
  68. }
  69. }
  70. private void RenderJsonList(HttpContext context)
  71. {
  72. context.Response.ContentType = "text/javascript";
  73. Encoding encoding = new UTF8Encoding();
  74. context.Response.ContentEncoding = encoding;
  75. siteRoot = SiteUtils.GetNavigationSiteRoot();
  76. context.Response.Write("var tinyMCETemplateList = [");
  77. if (WebConfigSettings.AddSystemContentTemplatesAboveSiteTemplates) //true by default
  78. {
  79. RenderSystemTemplateItems(context);
  80. }
  81. List<ContentTemplate> templates = ContentTemplate.GetAll(siteSettings.SiteGuid);
  82. foreach (ContentTemplate t in templates)
  83. {
  84. context.Response.Write(comma);
  85. context.Response.Write("['" + t.Title + "','" + siteRoot + "/Services/TinyMceTemplates.ashx?g=" + t.Guid.ToString() + "','']");
  86. comma = ",";
  87. }
  88. if (WebConfigSettings.AddSystemContentTemplatesBelowSiteTemplates) //false by default
  89. {
  90. RenderSystemTemplateItems(context);
  91. }
  92. context.Response.Write("];");
  93. }
  94. private void RenderSystemTemplateItems(HttpContext context)
  95. {
  96. List<ContentTemplate> templates = SiteUtils.GetSystemContentTemplates();
  97. foreach (ContentTemplate t in templates)
  98. {
  99. context.Response.Write(comma);
  100. context.Response.Write("['" + t.Title + "','" + siteRoot + "/Services/TinyMceTemplates.ashx?g=" + t.Guid.ToString() + "','']");
  101. comma = ",";
  102. }
  103. }
  104. private void RenderTemplate(HttpContext context)
  105. {
  106. context.Response.ContentType = "text/html";
  107. Encoding encoding = new UTF8Encoding();
  108. context.Response.ContentEncoding = encoding;
  109. if (IsSystemTemplateGuid())
  110. {
  111. context.Response.Write(GetSystemTemplate());
  112. }
  113. else
  114. {
  115. ContentTemplate template = ContentTemplate.Get(templateGuid);
  116. if (template != null)
  117. {
  118. context.Response.Write(template.Body);
  119. }
  120. }
  121. }
  122. private string GetSystemTemplate()
  123. {
  124. List<ContentTemplate> templates = SiteUtils.GetSystemContentTemplates();
  125. Guid templateGuid = new Guid(templateGuidString);
  126. foreach (ContentTemplate t in templates)
  127. {
  128. if (t.Guid == templateGuid) { return t.Body; }
  129. }
  130. return string.Empty;
  131. }
  132. private bool IsSystemTemplateGuid()
  133. {
  134. if (templateGuidString == jQueryAccordionGuid) { return true; }
  135. if (templateGuidString == jQueryAccordionNoHeightGuid) { return true; }
  136. if (templateGuidString == jQueryTabsGuid) { return true; }
  137. if (templateGuidString == YuiTabsGuid) { return true; }
  138. if (templateGuidString == Columns2Over1Guid) { return true; }
  139. if (templateGuidString == Columns3Over1Guid) { return true; }
  140. if (templateGuidString == Columns4Over1Guid) { return true; }
  141. if (templateGuidString == faqGuid) { return true;}
  142. return false;
  143. }
  144. public bool IsReusable
  145. {
  146. get
  147. {
  148. return false;
  149. }
  150. }
  151. }
  152. }