PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/App_Code/CSCode/Utilities.cs

https://github.com/eiursuajr/minGit
C# | 1194 lines | 1014 code | 72 blank | 108 comment | 201 complexity | f95c8083c1e8e76b2bf220add78e4a86 MD5 | raw file
Possible License(s): JSON
  1. using System.Web.UI.WebControls;
  2. using System.Configuration;
  3. using System.Collections;
  4. using System.Linq;
  5. using System.Data;
  6. using System.Web.Caching;
  7. using System.Web;
  8. using System.Xml.Linq;
  9. using System.Web.UI;
  10. using System.Diagnostics;
  11. using System.Web.Security;
  12. using System;
  13. using System.Text;
  14. using Microsoft.VisualBasic;
  15. using System.Web.UI.HtmlControls;
  16. using System.Web.SessionState;
  17. using System.Text.RegularExpressions;
  18. using System.Web.Profile;
  19. using System.Collections.Generic;
  20. using System.Web.UI.WebControls.WebParts;
  21. using System.Collections.Specialized;
  22. using System.Web;
  23. using Ektron.Cms;
  24. using Ektron.Cms.Site;
  25. using Ektron.ASM.PluginManager;
  26. using Ektron.Cms.Common;
  27. using Microsoft.VisualBasic.CompilerServices;
  28. using Ektron.Cms.API;
  29. public class Utilities
  30. {
  31. public static string UniqueIdFieldName = "ekUserUniqueId";
  32. public static string SessionIdClassName = "ektronsessionidfield";
  33. public static void ProcessThumbnail(string SrcPath, string SrcFile)
  34. {
  35. ProcessThumbnail(SrcPath, SrcFile, 125, 125, 0);
  36. }
  37. public static void ProcessEcommThumbnail(string SrcPath, string SrcFile)
  38. {
  39. ProcessThumbnail(SrcPath, SrcFile, 125, 125, 0, "ecomm");
  40. }
  41. public static void RegisterBaseUrl(System.Web.UI.Page page)
  42. {
  43. ContentAPI api = new ContentAPI();
  44. Literal baseTag = new Literal();
  45. baseTag.Text = "<base href=\"" + HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ((Convert.ToInt32(HttpContext.Current.Request.ServerVariables["SERVER_PORT"]) == 80) ? "" : (":" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"])) + api.RequestInformationRef.SitePath + "\" />";
  46. page.Header.Controls.Add(baseTag);
  47. }
  48. public static bool ValidateUserLogin()
  49. {
  50. return ValidateUserLogin(true);
  51. }
  52. public static void AddSessionIdField(Control control)
  53. {
  54. if (control != null)
  55. {
  56. control.Controls.Add(GetSessionIdField());
  57. }
  58. }
  59. public static Control GetSessionIdField()
  60. {
  61. string sessionId = System.Web.HttpContext.Current.Session.SessionID;
  62. LiteralControl sessionIdField = new LiteralControl(
  63. string.Format(@"<input type=""hidden"" name=""{0}"" id=""{0}"" class=""{1}"" value=""{2}"" />",
  64. Guid.NewGuid().ToString(),
  65. SessionIdClassName,
  66. sessionId
  67. )
  68. );
  69. return sessionIdField;
  70. }
  71. public static Control GetUniqueIdField(int uniqueId)
  72. {
  73. LiteralControl uniqueIdField = new LiteralControl(
  74. string.Format(@"<input type=""hidden"" name=""{0}"" id=""{0}"" value=""{1}"" />", Utilities.UniqueIdFieldName, uniqueId)
  75. );
  76. return uniqueIdField;
  77. }
  78. public static bool IsInternalPostback
  79. {
  80. get {
  81. if (!(System.Web.HttpContext.Current.Handler as Page).IsPostBack)
  82. return false;
  83. ContentAPI cApi = new ContentAPI();
  84. bool isInternalPostback =
  85. System.Web.HttpContext.Current.Request.Form.Count > 0 &&
  86. System.Web.HttpContext.Current.Request.Form[UniqueIdFieldName] != null &&
  87. System.Web.HttpContext.Current.Request.Form[UniqueIdFieldName] == cApi.RequestInformationRef.UniqueId.ToString() &&
  88. (
  89. !(null == System.Web.HttpContext.Current.Request.UrlReferrer ||
  90. System.Web.HttpContext.Current.Request.Url.Authority != System.Web.HttpContext.Current.Request.UrlReferrer.Authority)
  91. );
  92. return isInternalPostback;
  93. }
  94. }
  95. public static bool ValidateUserLogin(bool redirect)
  96. {
  97. ContentAPI cApi = new ContentAPI();
  98. if ((cApi.EkContentRef).IsAllowed(0, 0, "users", "IsLoggedIn", cApi.UserId) == false)
  99. {
  100. if (redirect)
  101. System.Web.HttpContext.Current.Response.Redirect(cApi.AppPath + "login.aspx?fromLnkPg=1", false);
  102. return false;
  103. }
  104. return true;
  105. }
  106. public static bool ValidateUserRole(EkEnumeration.CmsRoleIds roleId)
  107. {
  108. return ValidateUserRole(roleId, true);
  109. }
  110. public static bool ValidateUserRole(EkEnumeration.CmsRoleIds roleId, bool redirect)
  111. {
  112. ContentAPI cApi = new ContentAPI();
  113. if (!cApi.IsARoleMember(roleId))
  114. {
  115. if (redirect)
  116. System.Web.HttpContext.Current.Response.Redirect(cApi.AppPath + "login.aspx?fromLnkPg=1", false);
  117. return false;
  118. }
  119. return true;
  120. }
  121. public static void ProcessThumbnail(string SrcPath, string SrcFile, int Width, int height, int ThumbSize)
  122. {
  123. ProcessThumbnail(SrcPath, SrcFile, Width, height, ThumbSize, "thumb");
  124. }
  125. public static void ProcessThumbnail(string SrcPath, string SrcFile, int Width, int height, int ThumbSize, string prefix)
  126. {
  127. string strSrcLoc = "";
  128. string strDesLoc = "";
  129. string strExtn = "png";
  130. bool result = false;
  131. try
  132. {
  133. strSrcLoc = SrcPath + "\\" + SrcFile;
  134. strExtn = SrcFile.Substring(SrcFile.Length - 3, 3);
  135. strExtn = strExtn.ToLower();
  136. if ("gif" == strExtn)
  137. {
  138. strExtn = "png";
  139. if (ThumbSize == 0)
  140. {
  141. strDesLoc = SrcPath + "\\thumb_" + SrcFile.Substring(0, SrcFile.Length - 3) + strExtn;
  142. }
  143. else
  144. {
  145. strDesLoc = SrcPath + "\\thumb" + ThumbSize + "_" + SrcFile.Substring(0, SrcFile.Length - 3) + strExtn;
  146. }
  147. }
  148. else
  149. {
  150. if (ThumbSize == 0)
  151. {
  152. strDesLoc = SrcPath + "\\thumb_" + SrcFile;
  153. }
  154. else
  155. {
  156. strDesLoc = SrcPath + "\\thumb" + ThumbSize + "_" + SrcFile;
  157. }
  158. }
  159. EkFileIO obj = new EkFileIO();
  160. result = obj.CreateThumbnail(strSrcLoc, strDesLoc, Width, height);
  161. if (result == false)
  162. {
  163. throw (new Exception("<p style=\'background-color:red\'>ERROR Initializing: </p>"));
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. throw (new Exception(ex.Message));
  169. }
  170. }
  171. /// --------------------------------------------------------------------------------
  172. /// <summary>
  173. /// Prepends Path to URL if URL is relative, otherwise returns URL as is.
  174. /// </summary>
  175. /// <param name="Path">
  176. /// Path to prepend to URL unless URL is already qualified, that is, not a relative path.
  177. /// Value Type: <see cref="String" /> (System.String)
  178. /// </param>
  179. /// <param name="URL">
  180. /// The URL to be qualified if it's not already.
  181. /// Value Type: <see cref="String" /> (System.String)
  182. /// </param>
  183. /// <returns>A qualified URL. <see cref="String" /> (System.String)</returns>
  184. /// <remarks>
  185. /// </remarks>
  186. /// --------------------------------------------------------------------------------
  187. public static string QualifyURL(string Path, string URL)
  188. {
  189. if ((Path == null) || string.Empty == Path)
  190. {
  191. return URL;
  192. }
  193. if ((URL == null) || string.Empty == URL)
  194. {
  195. return Path;
  196. }
  197. string strDelimiter;
  198. if (Path.IndexOf("/") >= 0 || URL.IndexOf("/") >= 0)
  199. {
  200. strDelimiter = "/";
  201. Path = Path.Replace("\\", strDelimiter);
  202. URL = URL.Replace("\\", strDelimiter);
  203. }
  204. else
  205. {
  206. strDelimiter = "\\";
  207. Path = Path.Replace("/", strDelimiter);
  208. URL = URL.Replace("/", strDelimiter);
  209. }
  210. if (URL.StartsWith(strDelimiter + strDelimiter) || URL.IndexOf(":") >= 0)
  211. {
  212. return URL;
  213. }
  214. else if (Path.EndsWith(strDelimiter) || URL.StartsWith(strDelimiter))
  215. {
  216. if (Path.EndsWith(strDelimiter) && URL.StartsWith(strDelimiter))
  217. {
  218. return Path + URL.Substring(strDelimiter.Length); // remove extra delimiter
  219. }
  220. else
  221. {
  222. return Path + URL;
  223. }
  224. }
  225. else
  226. {
  227. return Path + strDelimiter + URL;
  228. }
  229. }
  230. // calling FixId in EkFunctions
  231. public static string FixId(string Id)
  232. {
  233. return Ektron.Cms.Common.EkFunctions.FixId(Id);
  234. }
  235. public static void ShowError(string Message)
  236. {
  237. //http://support.microsoft.com/kb/q208427/
  238. //INFO: Maximum URL Length Is 2,083 Characters in Internet Explorer
  239. //View products that this article applies to.
  240. //Article ID : 208427
  241. // Last(Review) : May(12, 2003)
  242. //Revision : 2.0
  243. //This article was previously published under Q208427
  244. //SUMMARY
  245. //Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters, with a maximum path length of 2,048 characters. This limit applies to both POST and GET request URLs.
  246. //If you are using the GET method, you are limited to a maximum of 2,048 characters (minus the number of characters in the actual path, of course).
  247. //POST, however, is not limited by the size of the URL for submitting name/value pairs, because they are transferred in the header and not the URL.
  248. //RFC 2616, Hypertext Transfer Protocol -- HTTP/1.1 (ftp://ftp.isi.edu/in-notes/rfc2616.txt), does not specify any requirement for URL length.
  249. string strURL;
  250. int nDiff;
  251. SiteAPI m_refSiteAPI = new SiteAPI();
  252. const int MAX_URL_LENGTH = 2048;
  253. do
  254. {
  255. strURL = m_refSiteAPI.AppPath + "reterror.aspx?info=" + EkFunctions.UrlEncode(Message);
  256. nDiff = System.Convert.ToInt32(MAX_URL_LENGTH - strURL.Length);
  257. if (nDiff < 0)
  258. {
  259. // Shorten the message by a reasonable amount and try again.
  260. Message = Message.Substring(0, Message.Length + nDiff);
  261. }
  262. } while (nDiff < 0);
  263. System.Web.HttpContext.Current.Response.Redirect(strURL, false);
  264. }
  265. public static string SetPostBackPage(string FormAction)
  266. {
  267. return ("<script>document.forms[0].action = \"" + FormAction + "\";" + "document.forms[0].__VIEWSTATE.name = \'NOVIEWSTATE\';</script>");
  268. }
  269. public static string EditorScripts(string var2, string AppeWebPath, string BrowserCode)
  270. {
  271. StringBuilder result = new StringBuilder();
  272. if (!(BrowserCode == "ar" || BrowserCode == "da" || BrowserCode == "de" || BrowserCode == "en" || BrowserCode == "es" || BrowserCode == "fr" || BrowserCode == "he" || BrowserCode == "it" || BrowserCode == "ja" || BrowserCode == "ko" || BrowserCode == "nl" || BrowserCode == "pt" || BrowserCode == "ru" || BrowserCode == "sv" || BrowserCode == "zh"))
  273. {
  274. BrowserCode = "en";
  275. }
  276. result.Append("<script language=\"JavaScript1.2\">" + "\r\n");
  277. result.Append("var LicenseKeys = \"" + var2 + "\";" + "\r\n");
  278. result.Append("var eWebEditProPath = \"" + AppeWebPath + "\"; " + "\r\n");
  279. result.Append("var WIFXPath= \"" + AppeWebPath + "\";" + "\r\n");
  280. result.Append("var WebImageFXPath = \"" + AppeWebPath + "\";" + "\r\n");
  281. result.Append("var eWebEditProMsgsFilename = \"ewebeditpromessages\" + \"" + BrowserCode + "\"+ \".js\";" + "\r\n");
  282. result.Append("function InformationPassingParameters()" + "\r\n");
  283. result.Append("{" + "\r\n");
  284. result.Append("var strLoadPage = \"\";" + "\r\n");
  285. result.Append("var strParamChar = \"?\";" + "\r\n");
  286. result.Append("if(\"undefined\" != typeof eWebEditProPath)" + "\r\n");
  287. result.Append("{" + "\r\n");
  288. result.Append(" strLoadPage += strParamChar + \"instewep=\";" + "\r\n");
  289. result.Append("strLoadPage += eWebEditProPath;" + "\r\n");
  290. result.Append("strParamChar = \"&\";" + "\r\n");
  291. result.Append("}" + "\r\n");
  292. result.Append("else" + "\r\n");
  293. result.Append("{" + "\r\n");
  294. result.Append("strLoadPage += strParamChar + \"instewep=undefined\";" + "\r\n");
  295. result.Append("strParamChar = \"&\";" + "\r\n");
  296. result.Append("}" + "\r\n");
  297. result.Append(" if(\"undefined\" != typeof LicenseKeys)" + "\r\n");
  298. result.Append("{" + "\r\n");
  299. result.Append("strLoadPage += strParamChar + \"licnewep=\";" + "\r\n");
  300. result.Append("strLoadPage += LicenseKeys;" + "\r\n");
  301. result.Append("strParamChar = \"&\";" + "\r\n");
  302. result.Append("} " + "\r\n");
  303. result.Append("else" + "\r\n");
  304. result.Append("{" + "\r\n");
  305. result.Append("strLoadPage += strParamChar + \"licnewep=undefined\";" + "\r\n");
  306. result.Append("strParamChar = \"&\";" + "\r\n");
  307. result.Append("}" + "\r\n");
  308. result.Append("if(\"undefined\" != typeof WebImageFXPath)" + "\r\n");
  309. result.Append("{" + "\r\n");
  310. result.Append("if (WebImageFXPath.length > 0)" + "\r\n");
  311. result.Append("{" + "\r\n");
  312. result.Append("strLoadPage += \"&instwifx=\";" + "\r\n");
  313. result.Append("strLoadPage += WebImageFXPath;" + "\r\n");
  314. result.Append("strParamChar =\"&\";" + "\r\n");
  315. result.Append(" }" + "\r\n");
  316. result.Append(" }" + "\r\n");
  317. result.Append("if(\"undefined\" != typeof WifxLicenseKeys)" + "\r\n");
  318. result.Append("{" + "\r\n");
  319. result.Append("if (WifxLicenseKeys.length > 0)" + "\r\n");
  320. result.Append("{" + "\r\n");
  321. result.Append("strLoadPage += \"&licnwifx=\";" + "\r\n");
  322. result.Append("strLoadPage += WifxLicenseKeys;" + "\r\n");
  323. result.Append("strParamChar = \"&\";" + "\r\n");
  324. result.Append("}" + "\r\n");
  325. result.Append("}" + "\r\n");
  326. result.Append("return(strLoadPage);" + "\r\n");
  327. result.Append("}" + "\r\n");
  328. result.Append("</script>" + "\r\n");
  329. result.Append("<script language=\"JavaScript1.2\" src=\"" + AppeWebPath + "cms_ewebeditpro.js\"></script>" + "\r\n");
  330. //result.Append("<script language=""JavaScript1.2""> " & vbCrLf)
  331. //// The install popup was correctly created at the beginning
  332. //// (within the eWebEditProinstallPopupUrl variable)
  333. //// but it needs to be set into the installPopup.url value
  334. //// for it to automatically be used to install the editor.
  335. //// Otherwise, it sits in the variable doing nothing.
  336. //// eWebEditPro.parameters.installPopup.url = eWebEditProinstallPopupUrl + InformationPassingParameters();
  337. //result.Append("</script>" & vbCrLf)
  338. return (result.ToString());
  339. }
  340. public static string eWebEditProField(string EditorName, string FieldName, string SetContentType, string GetContentType, string ContentHtml)
  341. {
  342. StringBuilder result = new StringBuilder();
  343. if (EditorName != FieldName)
  344. {
  345. result.Append("<input type=\"hidden\" name=\"" + FieldName + "\" value=\"" + EkFunctions.HtmlEncode(ContentHtml) + "\">" + "\r\n");
  346. }
  347. result.Append("<script language=\"JavaScript1.2\" type=\"text/javascript\">" + "\r\n");
  348. result.Append("<!--" + "\r\n");
  349. result.Append("eWebEditPro.defineField(\"" + EditorName + "\", \"" + FieldName + "\", \"" + SetContentType + "\", \"" + GetContentType + "\");" + "\r\n");
  350. result.Append("//-->" + "\r\n");
  351. result.Append("</script>" + "\r\n");
  352. return (result.ToString());
  353. }
  354. public static string eWebEditProEditor(string FieldName, string Width, string Height, string ContentHtml)
  355. {
  356. StringBuilder result = new StringBuilder();
  357. result.Append("<input type=\"hidden\" name=\"" + FieldName + "\" value=\"" + EkFunctions.HtmlEncode(ContentHtml) + "\">");
  358. result.Append("<script language=\"JavaScript1.2\" type=\"text/javascript\">" + "\r\n");
  359. result.Append("<!--" + "\r\n");
  360. result.Append("eWebEditPro.create(\"" + FieldName + "\", \"" + Width + "\", \"" + Height + "\");" + "\r\n");
  361. result.Append("//-->" + "\r\n");
  362. result.Append("</script>");
  363. return (result.ToString());
  364. }
  365. public static string eWebEditProPopupButton(string ButtonName, string FieldName)
  366. {
  367. StringBuilder result = new StringBuilder();
  368. result.Append("<script language=\"JavaScript1.2\" type=\"text/javascript\">" + "\r\n");
  369. result.Append("<!--" + "\r\n");
  370. result.Append("eWebEditPro.createButton(\"" + ButtonName + "\", \"" + FieldName + "\");" + "\r\n");
  371. result.Append("//-->" + "\r\n");
  372. result.Append("</script>");
  373. return (result.ToString());
  374. }
  375. public static bool IsAsset(int lContentType, string strAssetID)
  376. {
  377. bool result = false;
  378. result = System.Convert.ToBoolean((Ektron.Cms.Common.EkConstants.ManagedAsset_Min <= lContentType & lContentType <= Ektron.Cms.Common.EkConstants.ManagedAsset_Max) || (Ektron.Cms.Common.EkConstants.Archive_ManagedAsset_Min <= lContentType & lContentType <= Ektron.Cms.Common.EkConstants.Archive_ManagedAsset_Max) || strAssetID.Length > 0);
  379. return (result);
  380. }
  381. public static bool IsAssetType(int lContentType)
  382. {
  383. bool result = false;
  384. result = System.Convert.ToBoolean((Ektron.Cms.Common.EkConstants.ManagedAsset_Min <= lContentType & lContentType <= Ektron.Cms.Common.EkConstants.ManagedAsset_Max) || (Ektron.Cms.Common.EkConstants.Archive_ManagedAsset_Min <= lContentType & lContentType <= Ektron.Cms.Common.EkConstants.Archive_ManagedAsset_Max));
  385. return (result);
  386. }
  387. public static bool IsBrowserIE()
  388. {
  389. return ((System.Web.HttpContext.Current.Request.Browser.Type.IndexOf("IE") != -1) ? true : false);
  390. }
  391. public static bool IsPc()
  392. {
  393. bool returnValue;
  394. string str;
  395. str = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];
  396. returnValue = System.Convert.ToBoolean((str.IndexOf("Windows") + 1 > 0) ? true : false);
  397. return returnValue;
  398. }
  399. public static bool IsMac()
  400. {
  401. return (!IsPc());
  402. }
  403. public static string StripHTML(string strText)
  404. {
  405. return ContentAPI.StripHTML(strText);
  406. }
  407. public static SitemapPath[] DeserializeSitemapPath(System.Collections.Specialized.NameValueCollection form, int language)
  408. {
  409. string xml = System.Web.HttpUtility.UrlDecode(System.Convert.ToString(form["saved_sitemap_path"]));
  410. System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  411. System.Xml.XmlNodeList nodes;
  412. Ektron.Cms.Common.SitemapPath[] ret = null;
  413. Ektron.Cms.Common.SitemapPath smpNode;
  414. int iCount = 0;
  415. try
  416. {
  417. xml = xml.Replace("&", "&amp;");
  418. doc.LoadXml(xml);
  419. nodes = doc.SelectNodes("sitemap/node");
  420. foreach (System.Xml.XmlNode node in nodes)
  421. {
  422. smpNode = new Ektron.Cms.Common.SitemapPath();
  423. smpNode.Title = System.Web.HttpUtility.HtmlDecode((string)(node.SelectSingleNode("title").InnerXml));
  424. smpNode.Url = System.Web.HttpUtility.HtmlDecode(node.SelectSingleNode("url").InnerXml);
  425. smpNode.Order = int.Parse(node.SelectSingleNode("order").InnerXml);
  426. smpNode.Description = System.Web.HttpUtility.HtmlDecode((string)(node.SelectSingleNode("description").InnerXml));
  427. smpNode.Language = language;
  428. iCount++;
  429. Array.Resize(ref ret, iCount + 1);
  430. ret[iCount] = smpNode;
  431. }
  432. }
  433. catch
  434. {
  435. }
  436. return ret;
  437. }
  438. public static int FindSitemapPath(Ektron.Cms.Common.SitemapPath[] sitemapPaths, SitemapPath sitemapPath)
  439. {
  440. //return -1 if not found
  441. int iRet = -1;
  442. int iLoop = 1;
  443. Ektron.Cms.Common.SitemapPath node;
  444. if (sitemapPath == null)
  445. {
  446. return -1;
  447. }
  448. if (sitemapPaths != null)
  449. {
  450. for (iLoop = 1; iLoop <= sitemapPaths.Length - 1; iLoop++)
  451. {
  452. node = sitemapPaths[iLoop];
  453. if ((node.Title == sitemapPath.Title) && (node.Url == sitemapPath.Url) && (node.FolderId == sitemapPath.FolderId))
  454. {
  455. iRet = iLoop;
  456. break;
  457. }
  458. }
  459. }
  460. return iRet;
  461. }
  462. public static bool IsDefaultXmlConfig(long xml_id, XmlConfigData[] active_list)
  463. {
  464. foreach (XmlConfigData xmlData in active_list)
  465. {
  466. if (xmlData.Id == xml_id)
  467. {
  468. if (xmlData.IsDefault)
  469. {
  470. return true;
  471. }
  472. else
  473. {
  474. return false;
  475. }
  476. }
  477. }
  478. return false;
  479. }
  480. public static bool IsHTMLDefault(XmlConfigData[] active_list)
  481. {
  482. foreach (XmlConfigData xmlData in active_list)
  483. {
  484. if (xmlData.IsDefault && xmlData.Id != 0)
  485. {
  486. return false;
  487. }
  488. }
  489. return true;
  490. }
  491. public static bool IsNonFormattedContentAllowed(XmlConfigData[] active_list)
  492. {
  493. return Ektron.Cms.Common.EkFunctions.IsNonFormattedContentAllowed(active_list);
  494. }
  495. public static long GetDefaultXmlConfig(long folder_id)
  496. {
  497. ContentAPI m_refContentApi = new ContentAPI();
  498. XmlConfigData[] active_list;
  499. active_list = m_refContentApi.GetEnabledXmlConfigsByFolder(folder_id);
  500. foreach (XmlConfigData xmlData in active_list)
  501. {
  502. if (xmlData.IsDefault)
  503. {
  504. return xmlData.Id;
  505. }
  506. }
  507. return 0;
  508. }
  509. public static void AddLBpaths(Microsoft.VisualBasic.Collection data)
  510. {
  511. ContentAPI apiCont = new ContentAPI();
  512. Ektron.Cms.Library.EkLibrary objLib;
  513. int lbICount;
  514. int lbFCount;
  515. Collection lb;
  516. Collection cLbs;
  517. lbICount = 0;
  518. lbFCount = 0;
  519. objLib = apiCont.EkLibraryRef;
  520. cLbs = objLib.GetAllLBPaths("images");
  521. if (cLbs.Count > 0)
  522. {
  523. foreach (Collection tempLoopVar_lb in cLbs)
  524. {
  525. lb = tempLoopVar_lb;
  526. lbICount++;
  527. data.Add(HttpContext.Current.Server.MapPath((string)(lb["LoadBalancePath"])), (string)("LoadBalanceImagePath_" + lbICount), null, null);
  528. }
  529. }
  530. data.Add(lbICount, "LoadBalanceImageCount", null, null);
  531. cLbs = null;
  532. lb = null;
  533. cLbs = objLib.GetAllLBPaths("files");
  534. if (cLbs.Count > 0)
  535. {
  536. foreach (Collection tempLoopVar_lb in cLbs)
  537. {
  538. lb = tempLoopVar_lb;
  539. lbFCount++;
  540. data.Add(HttpContext.Current.Server.MapPath((string)(lb["LoadBalancePath"])), (string)("LoadBalanceFilePath_" + lbFCount), null, null);
  541. }
  542. }
  543. data.Add(lbFCount, "LoadBalanceFileCount", null, null);
  544. cLbs = null;
  545. }
  546. //public static void AddLBpaths(Collection data)
  547. //{
  548. // ContentAPI apiCont = new ContentAPI();
  549. // Ektron.Cms.Library.EkLibrary objLib;
  550. // int lbICount;
  551. // int lbFCount;
  552. // Collection lb;
  553. // Collection cLbs;
  554. // lbICount = 0;
  555. // lbFCount = 0;
  556. // objLib = apiCont.EkLibraryRef;
  557. // cLbs = objLib.GetAllLBPaths("images");
  558. // if (cLbs.Count > 0)
  559. // {
  560. // foreach (Collection tempLoopVar_lb in cLbs)
  561. // {
  562. // lb = tempLoopVar_lb;
  563. // lbICount++;
  564. // data.Add(HttpContext.Current.Server.MapPath((string)(lb["LoadBalancePath"])), "LoadBalanceImagePath_" + lbICount, null, null);
  565. // }
  566. // }
  567. // data.Add(lbICount, "LoadBalanceImageCount", null, null);
  568. // cLbs = null;
  569. // lb = null;
  570. // cLbs = objLib.GetAllLBPaths("files");
  571. // if (cLbs.Count > 0)
  572. // {
  573. // foreach (Collection tempLoopVar_lb in cLbs)
  574. // {
  575. // lb = tempLoopVar_lb;
  576. // lbFCount++;
  577. // data.Add(HttpContext.Current.Server.MapPath((string)(lb["LoadBalancePath"])), "LoadBalanceFilePath_" + lbFCount, null, null);
  578. // }
  579. // }
  580. // data.Add(lbFCount, "LoadBalanceFileCount", null, null);
  581. // cLbs = null;
  582. //}
  583. //public static void SetLanguage(object api)
  584. //{
  585. // int ContentLanguage = -1;
  586. // if (!(System.Web.HttpContext.Current.Request.QueryString["LangType"] == null))
  587. // {
  588. // if (System.Web.HttpContext.Current.Request.QueryString["LangType"] != "")
  589. // {
  590. // ContentLanguage = Convert.ToInt32(System.Web.HttpContext.Current.Request.QueryString["LangType"]);
  591. // Ektron.Cms.API.SetCookieValue("LastValidLanguageID", ContentLanguage);
  592. // }
  593. // else
  594. // {
  595. // if (Ektron.Cms.API.GetCookieValue("LastValidLanguageID") != "")
  596. // {
  597. // ContentLanguage = Convert.ToInt32(Ektron.Cms.API.GetCookieValue("LastValidLanguageID"));
  598. // }
  599. // }
  600. // }
  601. // else
  602. // {
  603. // if (Ektron.Cms.API.GetCookieValue("LastValidLanguageID") != "")
  604. // {
  605. // ContentLanguage = Convert.ToInt32(Ektron.Cms.API.GetCookieValue("LastValidLanguageID"));
  606. // }
  607. // }
  608. // if (ContentLanguage == Ektron.Cms.Common.EkConstants.CONTENT_LANGUAGES_UNDEFINED)
  609. // {
  610. // Ektron.Cms.API.ContentLanguage = Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES;
  611. // }
  612. // else
  613. // {
  614. // Ektron.Cms.API.ContentLanguage = ContentLanguage;
  615. // }
  616. //}
  617. public static void SetLanguage(ContentAPI api)
  618. {
  619. int ContentLanguage = -1;
  620. if (!(System.Web.HttpContext.Current.Request.QueryString["LangType"] == null))
  621. {
  622. if (System.Web.HttpContext.Current.Request.QueryString["LangType"] != "")
  623. {
  624. ContentLanguage = Convert.ToInt32(System.Web.HttpContext.Current.Request.QueryString["LangType"]);
  625. api.SetCookieValue("LastValidLanguageID", ContentLanguage.ToString());
  626. }
  627. else
  628. {
  629. if (api.GetCookieValue("LastValidLanguageID") != "")
  630. {
  631. ContentLanguage = Convert.ToInt32(api.GetCookieValue("LastValidLanguageID"));
  632. }
  633. }
  634. }
  635. else
  636. {
  637. if (api.GetCookieValue("LastValidLanguageID") != "")
  638. {
  639. ContentLanguage = Convert.ToInt32(api.GetCookieValue("LastValidLanguageID"));
  640. }
  641. }
  642. if (ContentLanguage == Ektron.Cms.Common.EkConstants.CONTENT_LANGUAGES_UNDEFINED)
  643. {
  644. api.ContentLanguage = Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES;
  645. }
  646. else
  647. {
  648. api.ContentLanguage = ContentLanguage;
  649. }
  650. }
  651. public static void SetLanguage(CommonApi api)
  652. {
  653. int ContentLanguage = -1;
  654. if (!(System.Web.HttpContext.Current.Request.QueryString["LangType"] == null))
  655. {
  656. if (System.Web.HttpContext.Current.Request.QueryString["LangType"] != "")
  657. {
  658. ContentLanguage = Convert.ToInt32(System.Web.HttpContext.Current.Request.QueryString["LangType"]);
  659. api.SetCookieValue("LastValidLanguageID", ContentLanguage.ToString());
  660. }
  661. else
  662. {
  663. if (api.GetCookieValue("LastValidLanguageID") != "")
  664. {
  665. ContentLanguage = Convert.ToInt32(api.GetCookieValue("LastValidLanguageID"));
  666. }
  667. }
  668. }
  669. else
  670. {
  671. if (api.GetCookieValue("LastValidLanguageID") != "")
  672. {
  673. ContentLanguage = Convert.ToInt32(api.GetCookieValue("LastValidLanguageID"));
  674. }
  675. }
  676. if (ContentLanguage == Ektron.Cms.Common.EkConstants.CONTENT_LANGUAGES_UNDEFINED)
  677. {
  678. api.ContentLanguage = Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES;
  679. }
  680. else
  681. {
  682. api.ContentLanguage = ContentLanguage;
  683. }
  684. }
  685. public static void SetLanguage(SiteAPI api)
  686. {
  687. int ContentLanguage = -1;
  688. if (!(System.Web.HttpContext.Current.Request.QueryString["LangType"] == null))
  689. {
  690. if (System.Web.HttpContext.Current.Request.QueryString["LangType"] != "")
  691. {
  692. ContentLanguage = Convert.ToInt32(System.Web.HttpContext.Current.Request.QueryString["LangType"]);
  693. api.SetCookieValue("LastValidLanguageID", ContentLanguage.ToString());
  694. }
  695. else
  696. {
  697. if (api.GetCookieValue("LastValidLanguageID") != "")
  698. {
  699. ContentLanguage = Convert.ToInt32(api.GetCookieValue("LastValidLanguageID"));
  700. }
  701. }
  702. }
  703. else
  704. {
  705. if (api.GetCookieValue("LastValidLanguageID") != "")
  706. {
  707. ContentLanguage = Convert.ToInt32(api.GetCookieValue("LastValidLanguageID"));
  708. }
  709. }
  710. if (ContentLanguage == Ektron.Cms.Common.EkConstants.CONTENT_LANGUAGES_UNDEFINED)
  711. {
  712. api.ContentLanguage = Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES;
  713. }
  714. else
  715. {
  716. api.ContentLanguage = ContentLanguage;
  717. }
  718. }
  719. public static int GetLanguageId()
  720. {
  721. int languageId = 0;
  722. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["LangType"]) && int.TryParse(HttpContext.Current.Request.QueryString["LangType"], out languageId) && languageId > 0)
  723. {
  724. return languageId;
  725. }
  726. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Cookies != null) && HttpContext.Current.Request.Cookies.Count > 0 && !string.IsNullOrEmpty((string)(HttpContext.Current.Request.Cookies["ecm"]["LastValidLanguageID"])) && int.TryParse((string)(HttpContext.Current.Request.Cookies["ecm"]["LastValidLanguageID"]), out languageId) && languageId > 0)
  727. {
  728. return languageId;
  729. }
  730. return 0;
  731. }
  732. public static int GetLanguageId(ContentAPI capi)
  733. {
  734. int languageId = GetLanguageId();
  735. if (languageId > 0)
  736. {
  737. return languageId;
  738. }
  739. if (capi == null)
  740. {
  741. return 0;
  742. }
  743. if (capi.RequestInformationRef.ContentLanguage > 0)
  744. {
  745. return capi.RequestInformationRef.ContentLanguage;
  746. }
  747. return capi.RequestInformationRef.DefaultContentLanguage;
  748. }
  749. //Gets the setting in web.config that allows/disallows executing developer samples
  750. public static bool AllowExecDevSamples()
  751. {
  752. bool returnValue;
  753. bool value = false;
  754. if (ConfigurationManager.AppSettings["ek_EnableDeveloperSamples"] != null)
  755. {
  756. value = System.Convert.ToBoolean(ConfigurationManager.AppSettings["ek_EnableDeveloperSamples"].ToString());
  757. }
  758. returnValue = value;
  759. return returnValue;
  760. }
  761. //Redirect to a information page if key is not set in web.config
  762. public static void CheckDevSampleEnabled()
  763. {
  764. if (!AllowExecDevSamples())
  765. {
  766. SiteAPI m_refSiteAPI = new SiteAPI();
  767. string strURL;
  768. strURL = m_refSiteAPI.SitePath + "Developer/InfoDevSample.aspx";
  769. HttpContext.Current.Response.Redirect(strURL, false);
  770. }
  771. }
  772. public static string GetMembershipAddContentJavascript(long folder_id, int lang_id, int height, int width)
  773. {
  774. return GetMembershipAddContentJavascript(folder_id, lang_id, height, width, 0);
  775. }
  776. public static string GetMembershipAddContentJavascript(long folder_id, int lang_id, int height, int width, long DefaultTaxonomyID)
  777. {
  778. SiteAPI m_refSiteAPI = new SiteAPI();
  779. StringBuilder str = new StringBuilder();
  780. string TaxonomyQuery = "";
  781. if ((HttpContext.Current.Request.QueryString["taxonomyid"] != null) && HttpContext.Current.Request.QueryString["taxonomyid"] != "")
  782. {
  783. TaxonomyQuery = (string)("&amp;taxonomyid=" + HttpContext.Current.Request.QueryString["taxonomyid"]);
  784. }
  785. else if (DefaultTaxonomyID > 0)
  786. {
  787. TaxonomyQuery = (string)("&amp;taxonomyid=" + DefaultTaxonomyID);
  788. }
  789. if (lang_id == -1 || lang_id == 0)
  790. {
  791. lang_id = m_refSiteAPI.RequestInformationRef.DefaultContentLanguage;
  792. }
  793. str.Append("{");
  794. str.Append("var cToolBar = \'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=");
  795. str.Append((short)width);
  796. str.Append(",height=");
  797. str.Append((short)height);
  798. str.Append("\';");
  799. str.Append("var url=\'");
  800. str.Append(m_refSiteAPI.AppPath);
  801. if (m_refSiteAPI.RequestInformationRef.IsMembershipUser == 1)
  802. {
  803. str.Append("/membership_add_content.aspx?mode=add&amp;mode_id=" + folder_id + "&amp;lang_id=" + lang_id + "\';");
  804. }
  805. else
  806. {
  807. str.Append("/edit.aspx?close=true" + TaxonomyQuery + "&ContType=1&LangType=" + m_refSiteAPI.RequestInformationRef.ContentLanguage + "&type=add&createtask=1&id=" + folder_id + "&AllowHTML=1\';");
  808. }
  809. str.Append("var taxonomyselectedtree = 0; ");
  810. str.Append("if (document.getElementById(\'taxonomyselectedtree\') != null) {");
  811. str.Append("taxonomyselectedtree = document.getElementById(\'taxonomyselectedtree\').value;");
  812. str.Append("}");
  813. str.Append(" if (taxonomyselectedtree >0) {url = url + \'&seltaxonomyid=\' + taxonomyselectedtree;} ");
  814. str.Append("var popupwin = window.open(url, \'Edit\', cToolBar);");
  815. str.Append("return popupwin; };return false;");
  816. return str.ToString();
  817. }
  818. public static string GetMembershipAddContentJavascript(long folder_id)
  819. {
  820. return Utilities.GetMembershipAddContentJavascript(folder_id, 0);
  821. }
  822. public static string GetMembershipAddContentJavascript(long folder_id, int lang_id)
  823. {
  824. int height = 660;
  825. int width = 790;
  826. return Utilities.GetMembershipAddContentJavascript(folder_id, lang_id, height, width);
  827. }
  828. public static string GetMembershipAddContentJavascript(long folder_id, int height, int width)
  829. {
  830. return Utilities.GetMembershipAddContentJavascript(folder_id, 0, height, width);
  831. }
  832. public static string GetAssetDownloadLink(long content_id)
  833. {
  834. Ektron.Cms.ContentAPI content_api = null;
  835. ContentData content_data = null;
  836. try
  837. {
  838. content_api = new Ektron.Cms.ContentAPI();
  839. content_data = content_api.GetContentById(content_id, 0);
  840. if (content_data.AssetData == null || content_data.AssetData.Id.Trim().Length == 0)
  841. {
  842. return string.Empty;
  843. }
  844. return content_api.RequestInformationRef.ApplicationPath + "/DownloadAsset.aspx?id=" + content_id;
  845. }
  846. catch (Exception)
  847. {
  848. return string.Empty;
  849. }
  850. }
  851. public static string AutoSummary(string sHTML)
  852. {
  853. return ContentAPI.AutoSummary(sHTML);
  854. }
  855. private static string FindFirstWords(string input, int howManyToFind)
  856. {
  857. return FindFirstWords(input, howManyToFind);
  858. }
  859. public static string WikiQLink(string strText, long folderID)
  860. {
  861. if (strText.Length > 0)
  862. {
  863. strText = Strings.Replace(strText, "[[", "<span style=\"color:blue;\" folderid=\"" + folderID + "\" class=\"MakeLink\" category=\"\" target=\"_self\" >", 1, -1, CompareMethod.Text);
  864. strText = Strings.Replace(strText, "]]", "</span>", 1, -1, CompareMethod.Text);
  865. }
  866. return (strText);
  867. }
  868. public static string BuildRegexToCheckMaxLength(int MaxLength)
  869. {
  870. // Example use:
  871. // RegularExpressionValidator.ValidationExpression = Utilities.BuildRegexToCheckMaxLength(iMaxContLength)
  872. //
  873. // Firefox 2.0 regular expression max repetition is 65535, that is, "{0,65535}"
  874. if (MaxLength <= 0)
  875. {
  876. throw (new ArgumentException("MaxLength must be positive", "MaxLength"));
  877. }
  878. StringBuilder strRegex = new StringBuilder();
  879. // Form if max <= 65535: ^[\w\W]{0,max}$
  880. // Form if max > 65535: ^([\w\W]{0,32768}){0,<%=max \ 32768%>}[\w\W]{0,<%=max Mod 32768%>}$
  881. // \w\W means any character including new line
  882. // Example,
  883. // 768000 => ^([\w\W]{0,32768}){0,23}[\w\W]{0,14336}$
  884. strRegex.Append("^");
  885. if (MaxLength > 65535)
  886. {
  887. strRegex.Append("([\\w\\W]{0,32768}){0,");
  888. strRegex.Append(Convert.ToString(MaxLength / 32768)); // quotient
  889. strRegex.Append("}");
  890. }
  891. strRegex.Append("[\\w\\W]{0,");
  892. if (MaxLength <= 65535)
  893. {
  894. strRegex.Append(MaxLength.ToString());
  895. }
  896. else
  897. {
  898. strRegex.Append(Convert.ToString(MaxLength % 32768)); // remainder
  899. }
  900. strRegex.Append("}$");
  901. return strRegex.ToString();
  902. }
  903. public static Ektron.Telerik.WebControls.EditorStripFormattingOptions MSWordFilterOptions(SettingsData settings_data)
  904. {
  905. Ektron.Telerik.WebControls.EditorStripFormattingOptions ConfigSetting = Ektron.Telerik.WebControls.EditorStripFormattingOptions.MSWord;
  906. if (settings_data.PreserveWordStyles && settings_data.PreserveWordClasses)
  907. {
  908. ConfigSetting = Ektron.Telerik.WebControls.EditorStripFormattingOptions.MSWordPreserveStyles;// +Ektron.Telerik.WebControls.EditorStripFormattingOptions.MSWordPreserveClasses;
  909. }
  910. else if (true == settings_data.PreserveWordStyles)
  911. {
  912. ConfigSetting = Ektron.Telerik.WebControls.EditorStripFormattingOptions.MSWordPreserveStyles;
  913. }
  914. else if (true == settings_data.PreserveWordClasses)
  915. {
  916. ConfigSetting = Ektron.Telerik.WebControls.EditorStripFormattingOptions.MSWordPreserveClasses;
  917. }
  918. return ConfigSetting;
  919. }
  920. public static string GetEditorPreference(System.Web.HttpRequest Request)
  921. {
  922. //TODO: Move the editor choices to an xml file specified by the server then key the possible values
  923. //off of a matrix setup in the xml file based on OS version and browser version
  924. string SelectedEditControl = "ContentDesigner";
  925. bool IsMac = false;
  926. try
  927. {
  928. if (Request.Browser.Platform.IndexOf("Win") == -1)
  929. {
  930. IsMac = true;
  931. }
  932. //Which Editor
  933. if (IsMac)
  934. {
  935. if (ConfigurationManager.AppSettings["ek_EditControlMac"] != null)
  936. {
  937. SelectedEditControl = (string)(ConfigurationManager.AppSettings["ek_EditControlMac"].ToString());
  938. }
  939. }
  940. else
  941. {
  942. if (ConfigurationManager.AppSettings["ek_EditControlWin"] != null)
  943. {
  944. SelectedEditControl = (string)(ConfigurationManager.AppSettings["ek_EditControlWin"].ToString());
  945. }
  946. if (SelectedEditControl.ToLower() == "userpreferred")
  947. {
  948. CommonApi api = new CommonApi();
  949. if (api.RequestInformationRef.UserEditorType == Ektron.Cms.Common.EkEnumeration.UserEditorType.ewebeditpro)
  950. {
  951. SelectedEditControl = "eWebEditPro";
  952. }
  953. else
  954. {
  955. SelectedEditControl = "ContentDesigner";
  956. }
  957. }
  958. }
  959. }
  960. catch (Exception)
  961. {
  962. SelectedEditControl = "ContentDesigner";
  963. }
  964. return SelectedEditControl;
  965. }
  966. public static bool GetTemporaryMarkersPreference(System.Web.HttpRequest Request)
  967. {
  968. bool ShowTemporaryMarkers = true;
  969. try
  970. {
  971. if (ConfigurationManager.AppSettings["ek_ShowTemporaryMarkers"] != null)
  972. {
  973. bool.TryParse(ConfigurationManager.AppSettings["ek_ShowTemporaryMarkers"].ToString(), out ShowTemporaryMarkers);
  974. }
  975. }
  976. catch (Exception)
  977. {
  978. ShowTemporaryMarkers = true;
  979. }
  980. return ShowTemporaryMarkers;
  981. }
  982. public static string IsChecked(string val1, string val2)
  983. {
  984. if (val1.ToLower() == val2.ToLower())
  985. {
  986. return (" checked=\"checked\" ");
  987. }
  988. else
  989. {
  990. return ("");
  991. }
  992. }
  993. public static string IsSelected(string val1, string val2)
  994. {
  995. if (val1.ToLower() == val2.ToLower())
  996. {
  997. return (" selected=\"selected\" ");
  998. }
  999. else
  1000. {
  1001. return ("");
  1002. }
  1003. }
  1004. public static string GetCorrectThumbnailFileWithExtn(string sFilename)
  1005. {
  1006. string[] aTemp = sFilename.Split('.');
  1007. string sRet = "";
  1008. try
  1009. {
  1010. if (aTemp.Length > 1)
  1011. {
  1012. if (aTemp[(aTemp.Length - 1)].ToLower() == "gif")
  1013. {
  1014. aTemp[(aTemp.Length - 1)] = "png";
  1015. sRet = string.Join(".", aTemp);
  1016. }
  1017. else
  1018. {
  1019. sRet = sFilename;
  1020. }
  1021. }
  1022. }
  1023. catch (Exception)
  1024. {
  1025. sRet = sFilename;
  1026. }
  1027. return sRet;
  1028. }
  1029. public static void DisableActionRewrite(HttpContext context)
  1030. {
  1031. if (context.Items["ActionAlreadyWritten"] == null)
  1032. {
  1033. context.Items["ActionAlreadyWritten"] = true;
  1034. }
  1035. }
  1036. public static string GetFolderImage(EkEnumeration.FolderType type, string applicationImagePath)
  1037. {
  1038. string imageURL = applicationImagePath;
  1039. if (type == Ektron.Cms.Common.EkEnumeration.FolderType.Community)
  1040. {
  1041. imageURL += "images/ui/icons/folderCommunity.png";
  1042. }
  1043. else if (type == Ektron.Cms.Common.EkEnumeration.FolderType.Catalog)
  1044. {
  1045. imageURL += "images/ui/icons/folderGreen.png";
  1046. }
  1047. else
  1048. {
  1049. imageURL += "images/ui/icons/folder.png";
  1050. }
  1051. return imageURL;
  1052. }
  1053. public static string GetProductImage(EkEnumeration.CatalogEntryType entryType, string applicationImagePath)
  1054. {
  1055. string productImage = applicationImagePath;
  1056. if (entryType == Ektron.Cms.Common.EkEnumeration.CatalogEntryType.Bundle)
  1057. {
  1058. productImage += "images/ui/icons/package.png";
  1059. }
  1060. else if (entryType == Ektron.Cms.Common.EkEnumeration.CatalogEntryType.ComplexProduct)
  1061. {
  1062. productImage += "images/ui/icons/bricks.png";
  1063. }
  1064. else if (entryType == Ektron.Cms.Common.EkEnumeration.CatalogEntryType.Kit)
  1065. {
  1066. productImage += "images/ui/icons/bulletGreen.png";
  1067. }
  1068. else if (entryType == Ektron.Cms.Common.EkEnumeration.CatalogEntryType.SubscriptionProduct)
  1069. {
  1070. productImage += "images/ui/icons/bookGreen.png";
  1071. }
  1072. else
  1073. {
  1074. productImage += "images/ui/icons/brick.png";
  1075. }
  1076. return productImage;
  1077. }
  1078. public enum WorkareaTree
  1079. {
  1080. Content,
  1081. Library,
  1082. Tax
  1083. }
  1084. public static void ReloadTree(Control control, Utilities.WorkareaTree[] trees, string idPath, long folderId)
  1085. {
  1086. System.Text.StringBuilder result = new System.Text.StringBuilder();
  1087. if (folderId > 0)
  1088. {
  1089. result
  1090. .Append("if (typeof (reloadFolder) == 'function'){")
  1091. .AppendFormat("reloadFolder({0});", folderId)
  1092. .Append("}")
  1093. .Append(Environment.NewLine);
  1094. }
  1095. foreach (Utilities.WorkareaTree tree in trees)
  1096. {
  1097. string treeType = tree.ToString() + "Tree";
  1098. idPath = GetFormattedTreePath(idPath).Replace("\\", "\\\\");
  1099. result.AppendFormat(
  1100. "top.TreeNavigation(\"{0}\", \"{1}\");",
  1101. treeType,
  1102. idPath
  1103. ).Append(Environment.NewLine);
  1104. }
  1105. Ektron.Cms.Framework.UI.JavaScript.RegisterJavaScriptBlock(control, result.ToString(), false);
  1106. }
  1107. private static string GetFormattedTreePath(string folderPath)
  1108. {
  1109. List<string> folderList = new List<string>();
  1110. if (folderPath.IndexOf("/") > -1)
  1111. {
  1112. folderList.AddRange(folderPath.Split(new char[] { '/' }));
  1113. }
  1114. else
  1115. {
  1116. folderList.AddRange(folderPath.Split(new char[] { '\\' }));
  1117. }
  1118. folderList = folderList.FindAll(x => !string.IsNullOrEmpty(x));
  1119. return "\\" + string.Join("\\", folderList.ToArray());
  1120. }
  1121. }