PageRenderTime 9ms CodeModel.GetById 5ms app.highlight 48ms RepoModel.GetById 1ms app.codeStats 1ms

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